Educational materials

WiiLAB Example Code - Wiimote Class: Nunchuk State

Note: MATLAB R2007a or greater is required for this code to run correctly.

UpdateNunchukState

The UpdateNunchukState method calls all of the state methods for the Wiimote's Nunchuk extension. This ensures that all the data types contain the most recent data before the user attempts to access and use that data.

%  UpdateNunchukState
%  @param wiimote wiimote object
function UpdateNunchukState(wiimote)

    % Buttons
    wiimote.GetNunchukButtonsState();
    % Accel
    wiimote.GetNunchukAccelState();
    % Joystick
    wiimote.GetNunchukJoystickState();
            
end % UpdateNunchukState     

GetNunchukButtonsState

GetNunchukButtonsState is a simple method to update the Wiimote's NunchukButtons? struct to reflect the Nunchuk buttons being pressed at the time the function is called.

%  GetNunchukButtonsState
%  @param wiimote wiimote object
function GetNunchukButtonsState(wiimote)

    % Check Connection
    wiimote.CheckConnection();
            
    % Buttons
    buttons = wiimote.wm.GetNunchukButtonState();  
            
    wiimote.NunchukButtons.C = buttons(1);
    wiimote.NunchukButtons.Z = buttons(2);
    wiimote.rawNunchukButtons = buttons;

end % GetNunchukButtonsState

GetNunchukAccelState

GetNunchukAccelState is a simple method to update the Wiimote's NunchukAccel? struct to reflect the Nunchuk's current acceleration at the time the function is called.

%  GetNunchukAccelState
%  @param wiimote wiimote object
function GetNunchukAccelState(wiimote)

    % Check Connection
    wiimote.CheckConnection();
           
    % Accel
    accel = wiimote.wm.GetNunchukAccelState() * 9.8;
           
    wiimote.NunchukAccel.X = accel(1);
    wiimote.NunchukAccel.Y = accel(2);
    wiimote.NunchukAccel.Z = accel(3);
    wiimote.rawNunchukAccel = accel;
            
end % GetNunchukAccelState     

GetNunchukJoystickState

GetNunchukJoystickState is a simple method to update the Wiimote's NunchukJoystick? struct to reflect the current displacement of the Nunchuk's joystick.

%  GetNunchukJoystickState
%  @param wiimote wiimote object
function GetNunchukJoystickState(wiimote)

    % Check Connection
    wiimote.CheckConnection();
            
    % Joystick
    joystick = wiimote.wm.GetNunchukJoystickState();   
            
    wiimote.NunchukJoystick.X = joystick(1);
    wiimote.NunchukJoystick.Y = joystick(2);
    wiimote.rawNunchukJoystick = joystick;

end % GetNunchukJoystickState
r2 - 21 Jul 2008 - 02:13:14 - JordanBrindza
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Syndicate this site RSSATOM