CJoystick joystick;
public MeadowApp()
{
Console.WriteLine("Initializing ...");
joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());
for (int i = 0; i < 100; i++)
{
Console.WriteLine($"Position: {joystick.DigitalPosition}");
Console.WriteLine($"Pressed: {joystick.State}");
Thread.Sleep(50);
}
joystick.StartUpdating(TimeSpan.FromMilliseconds(100));
joystick.Updated += Joystick_Updated;
joystick.Clicked += Joystick_Clicked;
}
private void Joystick_Clicked(object sender, EventArgs e)
{
Console.WriteLine("Center clicked");
}
private void Joystick_Updated(object sender, IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition> e)
{
Console.WriteLine($"{e.New.Horizontal}, {e.New.Vertical}");
}