Educational materials

WiiLAB Example Code - getWiimoteButtons

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

Annotations

The getWiimoteButtons function allows the user to tell which buttons are currently being pressed on the Wiimote. The function returns an array of values, one for each button, allowing the user to determine if multiple buttons are being pressed simultaneously.

Usage

buttons = getWiimoteButtons();

Return

getWiimoteButtons will return an array of 11 elements. Each element corresponds to a button on the Wiimote as follows: [A B UP RIGHT DOWN LEFT PLUS MINUS HOME ONE TWO]. Each element will be true (1) (if pressed) and false (0) (if not pressed).

Example

The following snippet of code will execute the block inside the if statement if 'ONE' and 'TWO' are being pressed on the Wiimote at the time of function call.

buttons = getWiimoteButtons();
if ( buttons(10) && buttons(11) )
    disp('ONE and TWO are being pressed on the Wiimote');
end

Raw Source Code

The source code is also available as a .m file download at the bottom of the page.

function [A B UP RIGHT DOWN LEFT PLUS MINUS HOME ONE TWO] = getWiimoteButtons () 
% usage:    getWiimoteButtons ()
% purpose:  Gets the Button values from the wiimote (true if they are
%           pressed - false if they are not)
% note:     initializeWiimote() must be called before calling this function

global wiimote;

% update the wiimote state values
wiimote.GetButtonsState();

% assign outputs
A = wiimote.Buttons.A;
B = wiimote.Buttons.B;
UP = wiimote.Buttons.Up;
RIGHT = wiimote.Buttons.Right;
DOWN = wiimote.Buttons.Down;
LEFT = wiimote.Buttons.Left;
PLUS = wiimote.Buttons.Plus;
MINUS = wiimote.Buttons.Minus;
HOME = wiimote.Buttons.Home;
ONE = wiimote.Buttons.One;
TWO = wiimote.Buttons.Two;

end

-- JordanBrindza - 25 Jun 2008

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