Skip to main content

Meadow.Foundation.Sensors.Buttons.PushButton

PushButton
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet 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

Class PushButton

Represents a momentary push button with two states that uses interrupts to detect state change

Assembly: Meadow.Foundation.dll
View Source
Declaration
public class PushButton : PushButtonBase, IButton, ISensor<bool>, ISensor, IDisposable

Inheritance: System.Object -> Meadow.Foundation.Sensors.Buttons.PushButtonBase

Implements:
Meadow.Peripherals.Sensors.Buttons.IButton, Meadow.Peripherals.Sensors.ISensor<System.Boolean>, Meadow.Peripherals.Sensors.ISensor, System.IDisposable

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.

View Source
Declaration
public TimeSpan DebounceDuration { get; set; }

DigitalIn

Returns digital input port

View Source
Declaration
protected IDigitalInterruptPort DigitalIn { get; set; }

Fields

DefaultDebounceDuration

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

View Source
Declaration
public static readonly TimeSpan DefaultDebounceDuration

DefaultGlitchDuration

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

View Source
Declaration
public static readonly TimeSpan DefaultGlitchDuration

Implements

  • Meadow.Peripherals.Sensors.Buttons.IButton
  • Meadow.Peripherals.Sensors.ISensor<System.Boolean>
  • Meadow.Peripherals.Sensors.ISensor
  • System.IDisposable