Educational materials

WiiLAB Example Code - Acceleration Indicator

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

Annotations

The Acceleration Indicator creates a visual representation of the Wiimote's current acceleration values. The function will create a rod with a ball attached to the end that will be used to represent the acceleration. One end of the rod will be attached to the center of the given object while the other end (with the ball) will point in the direction of the Wiimote's Acceleration. The length of the rod is proportional to the magnitude of the acceleration.

Usage

initializeAccelIndicator(obj);
or
initializeAccelIndicator(obj, velDamping);

Example

The following snippet of code will initialize the Acceleration Indicator and attach it to the created circle. After the main program the indicator is closed.

circle = drawCircle(150, 150, 10);
initializeAccelIndicator(circle);

% Main Program

closeAccelerationIndicator();

Note

There is a second, optional, parameter to this function. We have termed it the velDamping or velocity damping coefficient variable. The default behavior of this program is to assume that the given object is being moved by the Wiimote's acceleration and redraws itself accordingly. If the object is being moved by a fraction of the velocity, you must include the second parameter to keep the indicator in the correct position. You can also attach it to a stationary object (or one that is moved by something other than the acceleration) by passing a 0 (zero) for the velDamping variable.

Raw Source Code

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

%% initializeAccelIndicator
function initializeAccelIndicator(obj, velDamping)
%   usage:      initializeAccelIndicator (obj, velDamping)
%   purpose:   Enables the AccelIndicator that is tethered to this obj.
%               The velDamping variable is used to keep the tethered
%               centered on the object. The default value is 1 (ie. the
%               object is moved based directly off the acceleration value
%               with no scaling)

global wiimote;

if(nargin < 2)
    velDamping = 1;
end

wiimote.InitializeAccelIndicator(obj, velDamping);


%% closeAccelIndicator
function closeAccelIndicator()
%   usage:      closeAccelIndicator (obj)
%   purpose:   Disables the AccelIndicator and deletes the current
%               AccelIndicator

global wiimote;

wiimote.CloseAccelIndicator();

-- JordanBrindza - 09 Jul 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