diff --git a/documentation/Documentation.pptx b/documentation/Documentation.pptx index 275b8a3..12e14e1 100644 Binary files a/documentation/Documentation.pptx and b/documentation/Documentation.pptx differ diff --git a/documentation/Two State Button Comparison.png b/documentation/Two State Button Comparison.png index 9e4b5eb..0d07f7f 100644 Binary files a/documentation/Two State Button Comparison.png and b/documentation/Two State Button Comparison.png differ diff --git a/examples/PushEventButton_Demo_03/PushEventButton_Demo_03.ino b/examples/PushEventButton_Demo_03/PushEventButton_Demo_03.ino new file mode 100644 index 0000000..30f802e --- /dev/null +++ b/examples/PushEventButton_Demo_03/PushEventButton_Demo_03.ino @@ -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); + } +} \ No newline at end of file diff --git a/library.properties b/library.properties index 615b992..4d4cfe6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ButtonSuite -version=2.0.0 +version=2.1.0 author=Lance A. Endres maintainer=Lance A. Endres sentence=A library for using a simple mechanical push (momentary) button as a momentary button, a latching button, a counter, an enumerator, and more. diff --git a/src/PushEventButton.cpp b/src/PushEventButton.cpp index 31fa902..07f1ce0 100644 --- a/src/PushEventButton.cpp +++ b/src/PushEventButton.cpp @@ -59,7 +59,7 @@ bool PushEventButton::pushed() { case CAPTUREPUSH: { - if (status == BUTTONSUITE::JUSTPRESSED) + if (status & BUTTONSUITE::JUSTPRESSED) { return true; } @@ -71,7 +71,19 @@ bool PushEventButton::pushed() case CAPTURERELEASE: { - if (status == BUTTONSUITE::BUTTONSTATUS::WASSHORTPRESSED || status == BUTTONSUITE::BUTTONSTATUS::WASLONGPRESSED) + if (status & (BUTTONSUITE::WASSHORTPRESSED | BUTTONSUITE::WASLONGPRESSED)) + { + return true; + } + else + { + return false; + } + } + + case CAPTUREBOTH: + { + if (status & (BUTTONSUITE::JUSTPRESSED | BUTTONSUITE::WASSHORTPRESSED | BUTTONSUITE::WASLONGPRESSED)) { return true; } diff --git a/src/PushEventButton.h b/src/PushEventButton.h index d128f4c..7a14cc2 100644 --- a/src/PushEventButton.h +++ b/src/PushEventButton.h @@ -50,7 +50,8 @@ class PushEventButton : public TwoStateButton enum CAPTURETYPE { CAPTUREPUSH, - CAPTURERELEASE + CAPTURERELEASE, + CAPTUREBOTH }; public: