PushButton

Simple push button sensor.

Info

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.

Sourcing

One of the most common push buttons are momentary tactile buttons and come in an array of sizes. Most commonly they have 4 leads, two of which are redundant and provide stability and mounting strength when soldered to a PCB, but some have only two leads.

Sample Circuit

The following circuit illustrates a push button wired in CircuitTerminationType.CommonGround configuration on digital pin 0:

API

Properties

public TimeSpan DebounceDuration { get; set; }

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.

Default time is 20 milliseconds, which should be good for most tactile push buttons.

public H.InterruptPort DigitalIn { get; private set; }

Returns the interrupt port that the pushbutton is configured on.

Events

public event EventHandler PressStarted

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

public event EventHandler PressEnded

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

public event EventHandler Clicked

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

Constructors

public PushButton(H.Cpu.Pin inputPin, CircuitTerminationType type, int debounceDuration = 20)

Instantiates a new PushButton on the specified inputPin, with the specified `CircuitTerminationType’, and optionally, a specified debounce duration.