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