Remarks
WiiNunchuck | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
WiiNunchuck nunchuck;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
nunchuck = new WiiNunchuck(Device.CreateI2cBus(WiiNunchuck.DefaultSpeed));
nunchuck.GetIdentification();
Resolver.Log.Info("Update");
//onetime update - could be used in a game loop
nunchuck.Update();
//check the state of a button
Resolver.Log.Info("C Button is " + (nunchuck.CButton.State == true ? "pressed" : "not pressed"));
//.NET events
nunchuck.CButton.Clicked += (s, e) => Resolver.Log.Info("C button clicked");
nunchuck.ZButton.Clicked += (s, e) => Resolver.Log.Info("Z button clicked");
nunchuck.AnalogStick.Updated += (s, e) => Resolver.Log.Info($"Analog Stick {e.New.Horizontal}, {e.New.Vertical}");
return Task.CompletedTask;
}
public override Task Run()
{
nunchuck.StartUpdating(TimeSpan.FromMilliseconds(200));
return Task.CompletedTask;
}
Sample project(s) available on GitHub
Wiring Example
To wire a WiiNunchuck to your Meadow board, connect the following:
WiiNunchuck | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
Characteristic | Locus |
---|---|
Inheritance | System.Object WiiExtensionControllerBase > WiiNunchuck |
Inherited Members | WiiExtensionControllerBase.DefaultSpeed WiiExtensionControllerBase.i2cPeripheral WiiExtensionControllerBase.readBuffer WiiExtensionControllerBase.samplingLock WiiExtensionControllerBase.SamplingTokenSource WiiExtensionControllerBase.IsSampling WiiExtensionControllerBase.Initialize() WiiExtensionControllerBase.GetIdentification() WiiExtensionControllerBase.StartUpdating(Nullable<TimeSpan>) WiiExtensionControllerBase.StopUpdating() |
Namespace | Meadow.Foundation.Sensors.Hid |
Assembly | WiiExtensionControllers.dll |
Syntax
public class WiiNunchuck : WiiExtensionControllerBase
Constructors
WiiNunchuck(II2cBus)
Creates a Wii Nunchuck object
Declaration
public WiiNunchuck(II2cBus i2cBus)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | the I2C bus connected to controller |
Properties
Acceleration3D
Acceleration data from accelerometer
Declaration
public Acceleration3D? Acceleration3D { get; protected set; }
Property Value
Type | Description |
---|---|
System.Nullable<Acceleration3D> |
AnalogStick
Analog jostick (8 bits of precision)
Declaration
public IAnalogJoystick AnalogStick { get; }
Property Value
Type | Description |
---|---|
IAnalogJoystick |
CButton
C Button
Declaration
public IButton CButton { get; }
Property Value
Type | Description |
---|---|
IButton |
ZButton
Z Button
Declaration
public IButton ZButton { get; }
Property Value
Type | Description |
---|---|
IButton |
Methods
Update()
Get the latest sensor data from the device
Declaration
public override void Update()