From 6147a340581546a4abc62aaaa3e5050dbd8a0ca9 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Thu, 21 May 2020 15:45:52 -0400 Subject: [PATCH] Changed the default stateForPressed and fixed example --- examples/buttonClass/buttonClass.ino | 10 ++++------ src/Bounce2.h | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/buttonClass/buttonClass.ino b/examples/buttonClass/buttonClass.ino index 56d5a57..c08bb59 100644 --- a/examples/buttonClass/buttonClass.ino +++ b/examples/buttonClass/buttonClass.ino @@ -18,7 +18,7 @@ #define BUTTON_PIN_B 3 -#define LED_PIN 13 +#define LED_PIN LED_BUILTIN // Instantiate a Button object Button buttonA = Button(); @@ -50,12 +50,10 @@ void loop() { buttonB.update(); - // TURN ON LED IF EITHER BUTTON IS PRESSED + // TOGGLE THE LED IF EITHER BUTTON IS PRESSED if ( buttonA.pressed() || buttonB.pressed() ) { - digitalWrite(LED_PIN, HIGH ); + digitalWrite(LED_PIN, !digitalRead(LED_PIN) ); } - else { - digitalWrite(LED_PIN, LOW ); - } + } diff --git a/src/Bounce2.h b/src/Bounce2.h index c264b21..f266cb2 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -215,10 +215,10 @@ class Bounce */ class Button : public Bounce{ protected: - bool stateForPressed = 0; + bool stateForPressed = 1; // public: /*! - @brief Create an instance of the Button class. + @brief Create an instance of the Button class. By default, the pressed state is matched to a HIGH electrical level. @code @@ -230,7 +230,7 @@ public: Button(){ } /*! - @brief Set the electrical state (HIGH/LOW) that corresponds to a physical press. + @brief Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default, the pressed state is matched to a HIGH electrical level. @param state The electrical state (HIGH/LOW) that corresponds to a physical press.