Remarks

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

The PushButton class represents a simple push button, such as a tactile momentary button. To get notified when it’s clicked, subscribe to the Clicked event. If you need to know when the button is held down, subscribe to the PressStarted and PressEnded events.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp()
    {
        PushButton pushButton;

        // Initialize by passing a IDigitalInputPort
        //IDigitalInputPort digitalInputPort = Device.CreateDigitalInputPort(
        //    Device.Pins.D08, 
        //    InterruptMode.EdgeBoth, 
        //    ResistorMode.InternalPullUp, 20);
        //pushButton = new PushButton(digitalInputPort);

        // Initialize by sending Device and Pins
        pushButton = new PushButton(
            Device,
            Device.Pins.D08,
            ResistorMode.InternalPullUp
        );

        pushButton.PressStarted += PushButtonPressStarted;
        pushButton.PressEnded += PushButtonPressEnded;
    }

    void PushButtonPressStarted(object sender, EventArgs e)
    {
        Console.WriteLine("Press Started...");
    }

    void PushButtonPressEnded(object sender, EventArgs e)
    {
        Console.WriteLine("Press Ended...");
    }
}

Sample projects available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Buttons.PushButton/PushButton_Fritzing.svg"

Characteristic Locus
Inheritance System.Object > PushButton
Implements IDisposable
Namespace Meadow.Foundation.Sensors.Buttons
Assembly Meadow.Foundation.dll

Syntax

public class PushButton : IButton, IDisposable

Constructors

PushButton(IDigitalInputController, IPin, ResistorMode)

Creates PushButton with a digital input pin connected on a IIOdevice, specifying if its using an Internal or External PullUp/PullDown resistor.

Declaration
public PushButton(IDigitalInputController device, IPin inputPin, ResistorMode resistorMode = null)

Parameters

Type Name Description
IDigitalInputController device
IPin inputPin
ResistorMode resistorMode

PushButton(IDigitalInputPort)

Creates PushButton with a pre-configured interrupt port

Declaration
public PushButton(IDigitalInputPort interruptPort)

Parameters

Type Name Description
IDigitalInputPort interruptPort

Fields

buttonPressStart

Maximum DateTime value when the button was just pushed

Declaration
protected DateTime buttonPressStart

Field Value

Type Description
DateTime

DefaultDebounceDuration

Default Debounce used on the PushButton Input if an InputPort is auto-created

Declaration
public static readonly TimeSpan DefaultDebounceDuration

Field Value

Type Description
TimeSpan

DefaultGlitchDuration

Default Glitch Filter used on the PushButton Input if an InputPort is auto-created

Declaration
public static readonly TimeSpan DefaultGlitchDuration

Field Value

Type Description
TimeSpan

DefaultLongPressThreshold

Default threshold for LongPress events

Declaration
public static readonly TimeSpan DefaultLongPressThreshold

Field Value

Type Description
TimeSpan

resistorMode

Resistor Type to indicate if

Declaration
protected ResistorMode resistorMode

Field Value

Type Description
ResistorMode

Properties

DebounceDuration

This duration controls the debounce filter. It also has the effect of rate limiting clicks. Decrease this time to allow users to click more quickly.

Declaration
public TimeSpan DebounceDuration { get; set; }

Property Value

Type Description
TimeSpan

DigitalIn

Returns digital input port.

Declaration
protected IDigitalInputPort DigitalIn { get; set; }

Property Value

Type Description
IDigitalInputPort

LongClickedThreshold

The minimum duration for a long press.

Declaration
public TimeSpan LongClickedThreshold { get; set; }

Property Value

Type Description
TimeSpan

state

Returns the current raw state of the switch.

Declaration
protected bool state { get; }

Property Value

Type Description
System.Boolean

State

Returns the sanitized state of the switch. If the switch is pressed, returns true, otherwise false.

Declaration
public bool State { get; }

Property Value

Type Description
System.Boolean

Methods

Dispose()

Disposes the Digital Input resources

Declaration
public void Dispose()

RaiseClicked()

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

Declaration
protected virtual void RaiseClicked()

RaiseLongClicked()

Raised when the button circuit is pressed for at least 500ms.

Declaration
protected virtual void RaiseLongClicked()

RaisePressEnded()

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

Declaration
protected virtual void RaisePressEnded()

RaisePressStarted()

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

Declaration
protected virtual void RaisePressStarted()

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 500ms.

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