upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

API for the Wii* Nunchuk controller. More...

Detailed Description

UPM module for the Wii Nunchuk controller. This module was tested with Wii Nunchuk connected to I2C via a Grove Wii Nunchuk adapter.

See http://wiibrew.org/wiki/Wiimote/Extension_Controllers and http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck for more details on the controller and its protocol.

A warning for the Grove Wii Nunchuk adapter: it has 2 traces on one side, and 3 traces on the other. Do not match these up with the Nunchuk connector's traces. The connector's 'Grove' should be on the same side as the Grove interface socket on the adapter.

nunchuck.jpg
// Instantiate a nunchuck controller bus 0
// always do this first
System.out.println("Initializing... ");
if (!nunchuck.init()) {
System.err.println("nunchuck->init() failed.");
return;
}
while (true) {
nunchuck.update();
System.out.println("stickX: " + nunchuck.getStickX() + ", stickY: "
+ nunchuck.getStickY());
System.out.println("accelX: " + nunchuck.getAccelX() + ", accelY: "
+ nunchuck.getAccelY() + ", accelZ: " + nunchuck.getAccelZ());
if (nunchuck.getButtonC())
System.out.println("Button C pressed");
else
System.out.println("Button C not pressed");
if (nunchuck.getButtonZ())
System.out.println("Button Z pressed");
else
System.out.println("Button Z not pressed");
Thread.sleep(1000);
}

Public Member Functions

synchronized void delete ()
 
 NUNCHUCK (int bus, short addr)
 
 NUNCHUCK (int bus)
 
boolean writeByte (short reg, short arg1)
 
int readBytes (short reg, byte[] buffer)
 
boolean init ()
 
void update ()
 
void setStickX (int value)
 
int getStickX ()
 
void setStickY (int value)
 
int getStickY ()
 
void setAccelX (int value)
 
int getAccelX ()
 
void setAccelY (int value)
 
int getAccelY ()
 
void setAccelZ (int value)
 
int getAccelZ ()
 
void setButtonC (boolean value)
 
boolean getButtonC ()
 
void setButtonZ (boolean value)
 
boolean getButtonZ ()
 

Constructor & Destructor Documentation

NUNCHUCK ( int  bus,
short  addr 
)

NUNCHUCK constructor

Parameters
busI2C bus to use
addrI2C address to use

Member Function Documentation

boolean init ( )

Initializes the controller. Here, we disable encryption after delaying for a time to ensure the controller is ready.

Returns
True if initialization is successful
void update ( )

Reads and updates the current state of the controller.

boolean writeByte ( short  reg,
short  arg1 
)

Writes value(s) into registers

Parameters
regRegister location to start writing into
byteByte to write
Returns
True if successful

The documentation for this class was generated from the following file: