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 System.Object As5013 > CJoystick
Implements IAnalogJoystick IButton
Inherited Members As5013.Interrupt As5013.DefaultSpeed As5013.IsHorizontalInverted As5013.IsVerticalInverted As5013.IsVerticalHorizonalSwapped As5013.Position As5013.DigitalPosition As5013.ReadSensor() As5013.StartUpdating(Nullable<TimeSpan>) As5013.StopUpdating() As5013.SetLowPowerMode(Byte) As5013.SetScalingFactor(Byte) As5013.InvertSpinning() As5013.SoftReset() As5013.DisableInterrupt() As5013.EnableInterrupt() As5013.SetDefaultConfiguration()
Namespace Meadow.Foundation.mikroBUS.Sensors.Hid
Assembly CJoystick.dll

Syntax

public class CJoystick : As5013, IAnalogJoystick, IButton

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

Properties

LongClickedThreshold

The minimum duration for a long press

Declaration
public TimeSpan LongClickedThreshold { get; set; }

Property Value

Type Description
TimeSpan

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
System.Boolean

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

LongClicked

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

Declaration
public event EventHandler LongClicked

Event Type

Type Description
EventHandler

PressEnded

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

Declaration
public event EventHandler PressEnded

Event Type

Type Description
EventHandler

PressStarted

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

Declaration
public event EventHandler PressStarted

Event Type

Type Description
EventHandler