Remarks

ThumbJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Hid.ThumbJoystick

Code Example

ThumbJoystick joystick;

public override Task Initialize()
{
    Console.WriteLine("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)
{
    Console.WriteLine($"Horizontal: {e.New.Horizontal:n2}, Vertical: {e.New.Vertical:n2}");
    Console.WriteLine($"Digital position: {joystick.DigitalPosition}");
}

Sample project(s) available on GitHub

Wiring Example

ThumbJoystick Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00
Characteristic Locus
Inheritance System.Object ObservableBase<AnalogJoystickPosition> SamplingSensorBase<AnalogJoystickPosition> AnalogJoystick > ThumbJoystick
Implements ISamplingSensor<AnalogJoystickPosition> IAnalogJoystick
Inherited Members AnalogJoystick.sampleCount AnalogJoystick.sampleIntervalMs AnalogJoystick.HorizontalInputPort AnalogJoystick.VerticalInputPort AnalogJoystick.IsHorizontalInverted AnalogJoystick.IsVerticalInverted AnalogJoystick.Position AnalogJoystick.DigitalPosition AnalogJoystick.Calibration AnalogJoystick.SetCenterPosition() AnalogJoystick.GetDigitalJoystickPosition() AnalogJoystick.ReadSensor() AnalogJoystick.StartUpdating(Nullable<TimeSpan>) AnalogJoystick.StopUpdating() SamplingSensorBase<AnalogJoystickPosition>.samplingLock SamplingSensorBase<AnalogJoystickPosition>.Updated SamplingSensorBase<AnalogJoystickPosition>.SamplingTokenSource SamplingSensorBase<AnalogJoystickPosition>.Conditions SamplingSensorBase<AnalogJoystickPosition>.IsSampling SamplingSensorBase<AnalogJoystickPosition>.UpdateInterval SamplingSensorBase<AnalogJoystickPosition>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<AnalogJoystickPosition>.Read() ObservableBase<AnalogJoystickPosition>.observers ObservableBase<AnalogJoystickPosition>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<AnalogJoystickPosition>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<AnalogJoystickPosition>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Grove.Sensors.Hid
Assembly ThumbJoystick.dll

Syntax

public class ThumbJoystick : AnalogJoystick, ISamplingSensor<AnalogJoystickPosition>, IAnalogJoystick

Constructors

ThumbJoystick(IAnalogInputPort, IAnalogInputPort, AnalogJoystick.JoystickCalibration)

Creates a ThumbJoystick driver

Declaration
public ThumbJoystick(IAnalogInputPort horizontalInputPort, IAnalogInputPort verticalInputPort, AnalogJoystick.JoystickCalibration calibration = null)

Parameters

Type Name Description
IAnalogInputPort horizontalInputPort
IAnalogInputPort verticalInputPort
AnalogJoystick.JoystickCalibration calibration

ThumbJoystick(IPin, IPin, AnalogJoystick.JoystickCalibration)

Creates a ThumbJoystick driver

Declaration
public ThumbJoystick(IPin horizontalPin, IPin verticalPin, AnalogJoystick.JoystickCalibration calibration = null)

Parameters

Type Name Description
IPin horizontalPin
IPin verticalPin
AnalogJoystick.JoystickCalibration calibration

Calibration for the joystick.

ThumbJoystick(IPin, IPin, AnalogJoystick.JoystickCalibration, Int32, TimeSpan)

Creates a ThumbJoystick driver

Declaration
public ThumbJoystick(IPin horizontalPin, IPin verticalPin, AnalogJoystick.JoystickCalibration calibration, int sampleCount, TimeSpan sampleInterval)

Parameters

Type Name Description
IPin horizontalPin
IPin verticalPin
AnalogJoystick.JoystickCalibration calibration

Calibration for the joystick.

System.Int32 sampleCount

How many samples to take during a given reading. These are automatically averaged to reduce noise.

TimeSpan sampleInterval

The time, in milliseconds, to wait in between samples during a reading.