Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object ObservableBase<AnalogJoystickPosition> SamplingSensorBase<AnalogJoystickPosition> As5013 > CJoystick
Implements IObservable<IChangeResult<AnalogJoystickPosition>> ISamplingSensor<AnalogJoystickPosition> ISensor<AnalogJoystickPosition> IAnalogJoystick II2cPeripheral IButton ISensor<bool>
Inherited Members As5013.Interrupt As5013.DefaultSpeed As5013.IsHorizontalInverted As5013.IsVerticalInverted As5013.IsVerticalHorizonalSwapped As5013.Position As5013.DigitalPosition As5013.DefaultI2cAddress As5013.i2cComms As5013.ReadSensor() As5013.StartUpdating(TimeSpan?) As5013.StopUpdating() As5013.SetLowPowerMode(byte) As5013.SetScalingFactor(byte) As5013.InvertSpinning() As5013.SoftReset() As5013.DisableInterrupt() As5013.EnableInterrupt() As5013.SetDefaultConfiguration() 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.mikroBUS.Sensors.Hid
Assembly CJoystick.dll

Syntax

public class CJoystick : As5013, IObservable<IChangeResult<AnalogJoystickPosition>>, ISamplingSensor<AnalogJoystickPosition>, ISensor<AnalogJoystickPosition>, IAnalogJoystick, II2cPeripheral, IButton, ISensor<bool>

Constructors

CJoystick(IPin, II2cBus)

Creates a mikroBUS Joystick Click board instance

Declaration
public CJoystick(IPin tstPin, II2cBus i2cBus)

Parameters

Type Name Description
IPin tstPin

TST pin

II2cBus i2cBus

I2C bus

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

Properties

LongClickedThreshold

The minimum duration for a long press

Declaration
public TimeSpan LongClickedThreshold { get; set; }

Property Value

Type Description
TimeSpan

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

State

Returns the raw state of the center push button If pressed - returns true, otherwise false

Declaration
public bool State { get; }

Property Value

Type Description
bool

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

Events

Clicked

Raised when the button circuit is re-opened after it has been closed (at the end of a “press”.

Declaration
public event EventHandler Clicked

Event Type

Type Description
EventHandler

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

LongClicked

Raised when the button circuit is pressed for at least LongClickedThreshold.

Declaration
public event EventHandler LongClicked

Event Type

Type Description
EventHandler

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

PressEnded

Raised when a press ends (the button is released; circuit is opened).

Declaration
public event EventHandler PressEnded

Event Type

Type Description
EventHandler

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub

PressStarted

Raised when a press starts (the button is pushed down; circuit is closed).

Declaration
public event EventHandler PressStarted

Event Type

Type Description
EventHandler

Remarks

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

Code Example

CJoystick joystick;

public MeadowApp()
{
    Console.WriteLine("Initializing ...");

    joystick = new CJoystick(Device.Pins.A02, Device.CreateI2cBus());

    //loop and read digital position 
    for (int i = 0; i < 100; i++)
    {
        Console.WriteLine($"Position: {joystick.DigitalPosition}");
        Console.WriteLine($"Pressed: {joystick.State}");

        Thread.Sleep(50);
    }

    //start continous reading
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

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

Sample project(s) available on GitHub