ThumbJoystick joystick;
public override Task Initialize()
{
Resolver.Log.Info("Initializing hardware...");
joystick = new ThumbJoystick(
Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
Device.CreateAnalogInputPort(Device.Pins.A02, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
null);
joystick.Updated += JoystickUpdated;
return Task.CompletedTask;
}
public override async Task Run()
{
await joystick.SetCenterPosition();
joystick.StartUpdating(TimeSpan.FromMilliseconds(20));
}
private void JoystickUpdated(object sender, IChangeResult<AnalogJoystickPosition> e)
{
Resolver.Log.Info($"Horizontal: {e.New.Horizontal:n2}, Vertical: {e.New.Vertical:n2}");
Resolver.Log.Info($"Digital position: {joystick.DigitalPosition}");
}