Meadow.Foundation.mikroBUS.Sensors.Hid.CJoystick
CJoystick | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
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
Class CJoystick
Represents a mikroBUS Joystick Click board
Assembly: CJoystick.dll
View Source
public class CJoystick : As5013, IObservable<IChangeResult<AnalogJoystickPosition>>, ISamplingSensor<AnalogJoystickPosition>, ISensor<AnalogJoystickPosition>, ISamplingSensor, IAnalogJoystick, II2cPeripheral, IButton, ISensor<bool>, ISensor
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
-> Meadow.Foundation.SamplingSensorBase<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
-> Meadow.Foundation.Sensors.Hid.As5013
Implements:
Expand
System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
, Meadow.Peripherals.Sensors.ISamplingSensor
, Meadow.Peripherals.Sensors.Hid.IAnalogJoystick
, Meadow.Hardware.II2cPeripheral
, Meadow.Peripherals.Sensors.Buttons.IButton
, Meadow.Peripherals.Sensors.ISensor<System.Boolean>
, Meadow.Peripherals.Sensors.ISensor
Properties
LongClickedThreshold
The minimum duration for a long press
View Source
public TimeSpan LongClickedThreshold { get; set; }
State
Returns the raw state of the center push button If pressed - returns true, otherwise false
View Source
public bool State { get; }
Events
PressStarted
Raised when a press starts (the button is pushed down; circuit is closed).
View Source
public event EventHandler PressStarted
Event Type
System.EventHandler
PressEnded
Raised when a press ends (the button is released; circuit is opened).
View Source
public event EventHandler PressEnded
Event Type
System.EventHandler
Clicked
Raised when the button circuit is re-opened after it has been closed (at the end of a “press”.
View Source
public event EventHandler Clicked
Event Type
System.EventHandler
LongClicked
Raised when the button circuit is pressed for at least LongClickedThreshold.
View Source
public event EventHandler LongClicked
Event Type
System.EventHandler
Implements
System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
Meadow.Peripherals.Sensors.ISamplingSensor
Meadow.Peripherals.Sensors.Hid.IAnalogJoystick
Meadow.Hardware.II2cPeripheral
Meadow.Peripherals.Sensors.Buttons.IButton
Meadow.Peripherals.Sensors.ISensor<System.Boolean>
Meadow.Peripherals.Sensors.ISensor