Meadow.Foundation.Sensors.Hid.WiiNunchuck
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.DefaultI2cSpeed));
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 |
Class WiiNunchuck
Represents a Nintendo Wii I2C Nunchuck
Assembly: WiiExtensionControllers.dll
View Source
Declaration
public class WiiNunchuck : WiiExtensionControllerBase, II2cPeripheral
Inheritance: System.Object
-> Meadow.Foundation.Sensors.Hid.WiiExtensionControllerBase
Implements:
Meadow.Hardware.II2cPeripheral
Properties
CButton
C Button
View Source
Declaration
public IButton CButton { get; }
ZButton
Z Button
View Source
Declaration
public IButton ZButton { get; }
AnalogStick
Analog joystick (8 bits of precision)
View Source
Declaration
public IAnalogJoystick AnalogStick { get; }
Acceleration3D
Acceleration data from accelerometer
View Source
Declaration
public Acceleration3D? Acceleration3D { get; protected set; }
Methods
Update()
Get the latest sensor data from the device
View Source
Declaration
public override void Update()
Implements
Meadow.Hardware.II2cPeripheral