-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated PushEventButton to allow for capturing both push and release.
Updated PushEventButton to allow for capturing both push and release.
- Loading branch information
Showing
6 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions
50
examples/PushEventButton_Demo_03/PushEventButton_Demo_03.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
This example demonstrates how the PushEventButton captures each individual | ||
button press as discrete events. It does not matter how long the button is | ||
pressed down or released. Only the transition between pressed and released | ||
is captured. | ||
The button should be wired such that when pressed, the "buttonPin" is | ||
connected to ground. | ||
The LED should be wired with the "ledPin" to the positive lead and the | ||
negative lead should be connected to ground. A current limiting resistor | ||
should be used. | ||
*/ | ||
|
||
#include "PushEventButton.h" | ||
|
||
// Change these if your button or LED are on other pins. | ||
int buttonPin = 8; | ||
int ledPin = 9; | ||
|
||
// The button will automatically configure the button pin. | ||
// Because the "CAPTUREBOTH" option is used, both the down push | ||
// and the release are captured and used to flash the LED. | ||
PushEventButton button(buttonPin, PushEventButton::CAPTUREBOTH); | ||
|
||
void setup() | ||
{ | ||
// Setup the output LED. | ||
pinMode(ledPin, OUTPUT); | ||
digitalWrite(ledPin, LOW); | ||
} | ||
|
||
void loop() | ||
{ | ||
// This will return true only once for each button push. | ||
// This example is triggered on the press of the button. As soon as the button is pressed down | ||
// this returns true. It does not matter how long the button is held down, the light flashes | ||
// for the same amount of time. Nothing happens on the button release. | ||
bool buttonPushed = button.pushed(); | ||
|
||
// Set the LED to the state of the button press. | ||
digitalWrite(ledPin, buttonPushed); | ||
|
||
if (buttonPushed) | ||
{ | ||
// If the button was pushed, the light will be turned on. We need a brief delay to make sure the | ||
// on state of the LED is long enough to be seen. | ||
delay(100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters