Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

Characteristic Locus
Inheritance object ObservableBase<AnalogJoystickPosition> SamplingSensorBase<AnalogJoystickPosition> > AnalogJoystick
Implements IObservable<IChangeResult<AnalogJoystickPosition>> ISamplingSensor<AnalogJoystickPosition> ISensor<AnalogJoystickPosition> IAnalogJoystick
Inherited Members SamplingSensorBase<AnalogJoystickPosition>.samplingLock SamplingSensorBase<AnalogJoystickPosition>.Updated SamplingSensorBase<AnalogJoystickPosition>.SamplingTokenSource SamplingSensorBase<AnalogJoystickPosition>.Conditions SamplingSensorBase<AnalogJoystickPosition>.IsSampling SamplingSensorBase<AnalogJoystickPosition>.UpdateInterval SamplingSensorBase<AnalogJoystickPosition>.RaiseEventsAndNotify(IChangeResult<AnalogJoystickPosition>) SamplingSensorBase<AnalogJoystickPosition>.Read() ObservableBase<AnalogJoystickPosition>.observers ObservableBase<AnalogJoystickPosition>.NotifyObservers(IChangeResult<AnalogJoystickPosition>) ObservableBase<AnalogJoystickPosition>.Subscribe(IObserver<IChangeResult<AnalogJoystickPosition>>) ObservableBase<AnalogJoystickPosition>.CreateObserver(Action<IChangeResult<AnalogJoystickPosition>>, Predicate<IChangeResult<AnalogJoystickPosition>>) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Sensors.Hid
Assembly Meadow.Foundation.dll

Syntax

public class AnalogJoystick : SamplingSensorBase<AnalogJoystickPosition>, IObservable<IChangeResult<AnalogJoystickPosition>>, ISamplingSensor<AnalogJoystickPosition>, ISensor<AnalogJoystickPosition>, IAnalogJoystick

Constructors

AnalogJoystick(IAnalogInputPort, IAnalogInputPort, JoystickCalibration?)

Creates a 2-axis analog joystick

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

Parameters

Type Name Description
IAnalogInputPort horizontalInputPort
IAnalogInputPort verticalInputPort
AnalogJoystick.JoystickCalibration calibration

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

AnalogJoystick(IPin, IPin, JoystickCalibration?)

Creates a 2-axis analog joystick

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

Parameters

Type Name Description
IPin horizontalPin
IPin verticalPin
AnalogJoystick.JoystickCalibration calibration

Calibration for the joystick.

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

AnalogJoystick(IPin, IPin, JoystickCalibration?, int, TimeSpan)

Creates a 2-axis analog joystick

Declaration
public AnalogJoystick(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.

int 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.

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

Fields

sampleCount

Number of samples used to calculate position

Declaration
protected int sampleCount

Field Value

Type Description
int

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

sampleIntervalMs

Interval between samples

Declaration
protected int sampleIntervalMs

Field Value

Type Description
int

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

Properties

Calibration

Callibration for 2-axis analog joystick

Declaration
public AnalogJoystick.JoystickCalibration Calibration { get; protected set; }

Property Value

Type Description
AnalogJoystick.JoystickCalibration

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

DigitalPosition

Digital position of joystick

Declaration
public DigitalJoystickPosition? DigitalPosition { get; }

Property Value

Type Description
DigitalJoystickPosition?

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

HorizontalInputPort

Analog port connected to horizonal joystick pin

Declaration
protected IAnalogInputPort HorizontalInputPort { get; set; }

Property Value

Type Description
IAnalogInputPort

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

IsHorizontalInverted

Is the horizontal / x-axis inverted

Declaration
public bool IsHorizontalInverted { get; set; }

Property Value

Type Description
bool

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

IsVerticalInverted

Is the vertical / y-axis inverted

Declaration
public bool IsVerticalInverted { get; set; }

Property Value

Type Description
bool

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

Position

Current position of analog joystick

Declaration
public AnalogJoystickPosition? Position { get; protected set; }

Property Value

Type Description
AnalogJoystickPosition?

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

VerticalInputPort

Analog port connected to vertical joystick pin

Declaration
protected IAnalogInputPort VerticalInputPort { get; set; }

Property Value

Type Description
IAnalogInputPort

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

Methods

GetDigitalJoystickPosition()

Translates an analog position into a digital position, taking into account the calibration information.

Declaration
protected DigitalJoystickPosition GetDigitalJoystickPosition()

Returns

Type Description
DigitalJoystickPosition

The digital joystick position as DigitalJoystickPosition

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

ReadSensor()

Convenience method to get the current temperature. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
protected override Task<AnalogJoystickPosition> ReadSensor()

Returns

Type Description
Task<AnalogJoystickPosition>

Overrides

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

SetCenterPosition()

sets the current position as the center position and saves to the calibration.

Declaration
public Task SetCenterPosition()

Returns

Type Description
Task

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

StartUpdating(TimeSpan?)

Starts continuously sampling the sensor.

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public override void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
TimeSpan? updateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified. The default is 5 seconds.

Overrides

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"

StopUpdating()

Stops sampling the joystick position

Declaration
public override void StopUpdating()

Overrides

Remarks

AnalogJoystick
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogJoystick? joystick;

public override Task Initialize()
{
    joystick = new AnalogJoystick(
        Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)),
        null);

    // assume that the stick is in the center when it starts up
    _ = joystick?.SetCenterPosition(); //fire and forget

    //==== Classic Events
    if (joystick != null)
    {
        joystick.Updated += JoystickUpdated;
    }

    //==== IObservable
    joystick?.StartUpdating(TimeSpan.FromMilliseconds(20));

    return Task.CompletedTask;
}

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}");
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Hid.AnalogJoystick/AnalogJoystick_Fritzing.png"