I had been hearing about the simplicity of the WiiMoteLib for a while, but since I hadn’t put the Wii through my hands I hadn’t been able to touch them, I finally have the WiiMote at home, and obviously I had to start messing around. This is a simple code on how to connect and take some accelerometer readings, ideal for getting into the use of this device.

First we connect with any program Bluetooth device manager, to the WiiMote by pressing buttons 1 and 2 at the same time, and we connect it as a mouse, human interface, HID, … or whatever your manager calls it.

Now it’s time to add the WiimoteLib.dll library as a reference to our project and we start to code, global variables are declared in the class we are programming:

privateWiimote mWiimote; WiimoteCollection mWC; privatedelegatevoidUpdateWiimoteStateDelegate(WiimoteChangedEventArgs args);

Once the objects with which we will work have been declared, we declare the functions in charge of management:

privatevoid HandleWiiMote()

{

int index = 1; mWC = newWiimoteCollection(); try {

//We search for all existing WiiMotes

mWC.FindAllWiimotes();

}

catch (Exception ex)

{

//We apply our error protocol (for example log4net)

}

 

//All WiiMotes are covered

foreach (Wiimote wm in mWC)

{

// We connect with the WiiMote

wm.WiimoteChanged += wm_WiimoteChanged; wm.Connect();

if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard) wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);

//We assign the LED number to turn on in WiiMote

wm.SetLEDs(index++);

}

}

void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)

{

UpdateState(e);

}

publicvoid UpdateState(WiimoteChangedEventArgs args)

{

 

WiimoteState ws = args.WiimoteState;

//With the controller as if you were playing MarioKart //Y = -0.9 Left -0.0 | 0 | 0.1 Right 0.9 //Z = -0.9 Decelerate -0.0 | 0 | 0.1 Speed up 0.9

if (ws.AccelState.Values.Y > 0.5) {

//You have turned the knob to the right, you can call the functions relevant to this action.

}

if (ws.AccelState.Values.Y < -0.5) {

//You have turned the knob to the left, you can call the functions relevant to this action.

}

if (ws.AccelState.Values.Z > 0.5) {

//You have turned the control forward, you can call the functions relevant to this action.

}

if (ws.AccelState.Values.Z < -0.5) {

//You have turned the knob back, you can call the functions relevant to this action.

}

}

From here you can continue working with the rest of the information provided by these libraries.