From a98dd29b4127b31eb2841687a0169f8d167a1a12 Mon Sep 17 00:00:00 2001 From: NoobTracker <63962365+NoobTracker@users.noreply.github.com> Date: Fri, 8 May 2020 16:41:48 +0200 Subject: [PATCH 01/46] Added Bounce2Button I added the Bounce2Button class which adds the functions setInvert(bool invert), pressed() and released() and changes read(). --- src/Bounce2.cpp | 276 +++++++++++++-------------- src/Bounce2.h | 423 +++++++++++++++++++++--------------------- src/Bounce2Button.cpp | 15 ++ src/Bounce2Button.h | 19 ++ 4 files changed, 382 insertions(+), 351 deletions(-) create mode 100644 src/Bounce2Button.cpp create mode 100644 src/Bounce2Button.h diff --git a/src/Bounce2.cpp b/src/Bounce2.cpp index 6509e94..b27e4be 100644 --- a/src/Bounce2.cpp +++ b/src/Bounce2.cpp @@ -1,138 +1,138 @@ -// Please read Bounce2.h for information about the liscence and authors - - -#include "Bounce2.h" - - - - -Bounce::Bounce() - : previous_millis(0) - , interval_millis(10) - , state(0) - , pin(0) -{} - -void Bounce::attach(int pin) { - this->pin = pin; - state = 0; - if (readCurrentState()) { - setStateFlag(DEBOUNCED_STATE | UNSTABLE_STATE); - } -#ifdef BOUNCE_LOCK_OUT - previous_millis = 0; -#else - previous_millis = millis(); -#endif -} - -void Bounce::attach(int pin, int mode){ - setPinMode(pin, mode); - this->attach(pin); -} - -void Bounce::interval(uint16_t interval_millis) -{ - this->interval_millis = interval_millis; -} - -bool Bounce::update() -{ - - unsetStateFlag(CHANGED_STATE); -#ifdef BOUNCE_LOCK_OUT - - // Ignore everything if we are locked out - if (millis() - previous_millis >= interval_millis) { - bool currentState = readCurrentState(); - if ( currentState != getStateFlag(DEBOUNCED_STATE) ) { - previous_millis = millis(); - changeState(); - } - } - - -#elif defined BOUNCE_WITH_PROMPT_DETECTION - // Read the state of the switch port into a temporary variable. - bool readState = readCurrentState(); - - - if ( readState != getStateFlag(DEBOUNCED_STATE) ) { - // We have seen a change from the current button state. - - if ( millis() - previous_millis >= interval_millis ) { - // We have passed the time threshold, so a new change of state is allowed. - // set the STATE_CHANGED flag and the new DEBOUNCED_STATE. - // This will be prompt as long as there has been greater than interval_misllis ms since last change of input. - // Otherwise debounced state will not change again until bouncing is stable for the timeout period. - changeState(); - } - } - - // If the readState is different from previous readState, reset the debounce timer - as input is still unstable - // and we want to prevent new button state changes until the previous one has remained stable for the timeout. - if ( readState != getStateFlag(UNSTABLE_STATE) ) { - // Update Unstable Bit to macth readState - toggleStateFlag(UNSTABLE_STATE); - previous_millis = millis(); - } - - -#else - // Read the state of the switch in a temporary variable. - bool currentState = readCurrentState(); - - - // If the reading is different from last reading, reset the debounce counter - if ( currentState != getStateFlag(UNSTABLE_STATE) ) { - previous_millis = millis(); - toggleStateFlag(UNSTABLE_STATE); - } else - if ( millis() - previous_millis >= interval_millis ) { - // We have passed the threshold time, so the input is now stable - // If it is different from last state, set the STATE_CHANGED flag - if (currentState != getStateFlag(DEBOUNCED_STATE) ) { - previous_millis = millis(); - - - changeState(); - } - } - - -#endif - - return changed(); - -} - -// WIP HELD -unsigned long Bounce::previousDuration() { - return durationOfPreviousState; -} - -unsigned long Bounce::duration() { - return (millis() - stateChangeLastTime); -} - -inline void Bounce::changeState() { - toggleStateFlag(DEBOUNCED_STATE); - setStateFlag(CHANGED_STATE) ; - durationOfPreviousState = millis() - stateChangeLastTime; - stateChangeLastTime = millis(); -} - -bool Bounce::read() -{ - return getStateFlag(DEBOUNCED_STATE); -} - -bool Bounce::rose() -{ - return getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); -} - -bool Bounce::fell() -{ - return !getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); -} +// Please read Bounce2.h for information about the liscence and authors + + +#include "Bounce2.h" + + + + +Bounce::Bounce() + : previous_millis(0) + , interval_millis(10) + , state(0) + , pin(0) +{} + +void Bounce::attach(int pin) { + this->pin = pin; + state = 0; + if (readCurrentState()) { + setStateFlag(DEBOUNCED_STATE | UNSTABLE_STATE); + } +#ifdef BOUNCE_LOCK_OUT + previous_millis = 0; +#else + previous_millis = millis(); +#endif +} + +void Bounce::attach(int pin, int mode){ + setPinMode(pin, mode); + this->attach(pin); +} + +void Bounce::interval(uint16_t interval_millis) +{ + this->interval_millis = interval_millis; +} + +bool Bounce::update() +{ + + unsetStateFlag(CHANGED_STATE); +#ifdef BOUNCE_LOCK_OUT + + // Ignore everything if we are locked out + if (millis() - previous_millis >= interval_millis) { + bool currentState = readCurrentState(); + if ( currentState != getStateFlag(DEBOUNCED_STATE) ) { + previous_millis = millis(); + changeState(); + } + } + + +#elif defined BOUNCE_WITH_PROMPT_DETECTION + // Read the state of the switch port into a temporary variable. + bool readState = readCurrentState(); + + + if ( readState != getStateFlag(DEBOUNCED_STATE) ) { + // We have seen a change from the current button state. + + if ( millis() - previous_millis >= interval_millis ) { + // We have passed the time threshold, so a new change of state is allowed. + // set the STATE_CHANGED flag and the new DEBOUNCED_STATE. + // This will be prompt as long as there has been greater than interval_misllis ms since last change of input. + // Otherwise debounced state will not change again until bouncing is stable for the timeout period. + changeState(); + } + } + + // If the readState is different from previous readState, reset the debounce timer - as input is still unstable + // and we want to prevent new button state changes until the previous one has remained stable for the timeout. + if ( readState != getStateFlag(UNSTABLE_STATE) ) { + // Update Unstable Bit to macth readState + toggleStateFlag(UNSTABLE_STATE); + previous_millis = millis(); + } + + +#else + // Read the state of the switch in a temporary variable. + bool currentState = readCurrentState(); + + + // If the reading is different from last reading, reset the debounce counter + if ( currentState != getStateFlag(UNSTABLE_STATE) ) { + previous_millis = millis(); + toggleStateFlag(UNSTABLE_STATE); + } else + if ( millis() - previous_millis >= interval_millis ) { + // We have passed the threshold time, so the input is now stable + // If it is different from last state, set the STATE_CHANGED flag + if (currentState != getStateFlag(DEBOUNCED_STATE) ) { + previous_millis = millis(); + + + changeState(); + } + } + + +#endif + + return changed(); + +} + +// WIP HELD +unsigned long Bounce::previousDuration() { + return durationOfPreviousState; +} + +unsigned long Bounce::duration() { + return (millis() - stateChangeLastTime); +} + +inline void Bounce::changeState() { + toggleStateFlag(DEBOUNCED_STATE); + setStateFlag(CHANGED_STATE) ; + durationOfPreviousState = millis() - stateChangeLastTime; + stateChangeLastTime = millis(); +} + +bool Bounce::read() +{ + return getStateFlag(DEBOUNCED_STATE); +} + +bool Bounce::rose() +{ + return getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); +} + +bool Bounce::fell() +{ + return !getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); +} diff --git a/src/Bounce2.h b/src/Bounce2.h index d634890..555492c 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -1,213 +1,210 @@ -/* - The MIT License (MIT) - - Copyright (c) 2013 thomasfredericks - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * - Main code by Thomas O Fredericks (tof@t-o-f.info) - Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway - * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/** - * @todo Make Bounce2 more abstract. Split it from the hardware layer. - * @body Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce. - */ - - -#ifndef Bounce2_h -#define Bounce2_h - -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif - -// Uncomment the following line for "LOCK-OUT" debounce method -//#define BOUNCE_LOCK_OUT - -// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method -//#define BOUNCE_WITH_PROMPT_DETECTION - -#include - -/** - @example bounce.ino - Simple example of the Bounce library that switches the debug LED when a button is pressed. -*/ - -/** - @example change.ino - This example toggles the debug LED (pin 13) on or off when a button on pin 2 is pressed. -*/ - -/** - @example bounce_multiple.ino - Detect the falling edge of multiple buttons. Eight buttons with internal pullups. Toggles a LED when any button is pressed. Buttons on pins 2,3,4,5,6,7,8,9 -*/ - -/** - @example bounce2buttons.ino - Example of two instances of the Bounce class that switches the debug LED when either one of the two buttons is pressed. - */ - -static const uint8_t DEBOUNCED_STATE = 0b00000001; -static const uint8_t UNSTABLE_STATE = 0b00000010; -static const uint8_t CHANGED_STATE = 0b00000100; - -/** - The Bounce class. - */ -class Bounce -{ - public: - -/*! - @brief Create an instance of the Bounce class. - - @code - - // Create an instance of the Bounce class. - Bounce() button; - - @endcode -*/ - Bounce(); - - -/*! - @brief Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT). - - @param pin - The pin that is to be debounced. - @param mode - A valid Arduino pin mode (INPUT, INPUT_PULLUP or OUTPUT). -*/ - void attach(int pin, int mode); - - /** - Attach to a pin for advanced users. Only attach the pin this way once you have previously set it up. Otherwise use attach(int pin, int mode). - */ - void attach(int pin); - - - /** - @brief Sets the debounce interval in milliseconds. - - @param interval_millis - The interval time in milliseconds. - - */ - void interval(uint16_t interval_millis); - - -/*! - @brief Updates the pin's state. - - Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your loop()). Only call update() once per loop(). - - @return True if the pin changed state. -*/ - - bool update(); - - /** - @brief Returns the pin's state (HIGH or LOW). - - @return HIGH or LOW. - */ - bool read(); - - /** - @brief Returns true if pin signal transitions from high to low. - */ - bool fell(); - - /** - @brief Returns true if pin signal transitions from low to high. - */ - bool rose(); - - - /** - @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 - */ - bool risingEdge() { return rose(); } - /** - @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 - */ - bool fallingEdge() { return fell(); } - /** - @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 - */ - Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() { - attach(pin); - interval(interval_millis); - } - - /** - @brief Returns the duration in milliseconds of the current state. - - Is reset to 0 once the pin rises ( rose() ) or falls ( fell() ). - - @return The duration in milliseconds (unsigned long) of the current state. - */ - - unsigned long duration(); - - /** - @brief Returns the duration in milliseconds of the previous state. - - Takes the values of duration() once the pin changes state. - - @return The duration in milliseconds (unsigned long) of the previous state. - */ - unsigned long previousDuration(); - - protected: - unsigned long previous_millis; - uint16_t interval_millis; - uint8_t state; - uint8_t pin; - unsigned long stateChangeLastTime; - unsigned long durationOfPreviousState; - virtual bool readCurrentState() { return digitalRead(pin); } - virtual void setPinMode(int pin, int mode) { -#if defined(ARDUINO_ARCH_STM32F1) - pinMode(pin, (WiringPinMode)mode); -#else - pinMode(pin, mode); -#endif - } - - private: - inline void changeState(); - inline void setStateFlag(const uint8_t flag) {state |= flag;} - inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;} - inline void toggleStateFlag(const uint8_t flag) {state ^= flag;} - inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);} - - public: - bool changed( ) { return getStateFlag(CHANGED_STATE); } - -}; - -#endif +/* + The MIT License (MIT) + + Copyright (c) 2013 thomasfredericks + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * + Main code by Thomas O Fredericks (tof@t-o-f.info) + Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway + * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/** + * @todo Make Bounce2 more abstract. Split it from the hardware layer. + * @body Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce. + */ + + +#ifndef Bounce2_h +#define Bounce2_h + +#if defined(ARDUINO) && ARDUINO >= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif + +// Uncomment the following line for "LOCK-OUT" debounce method +//#define BOUNCE_LOCK_OUT + +// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method +//#define BOUNCE_WITH_PROMPT_DETECTION + +#include + +/** + @example bounce.ino + Simple example of the Bounce library that switches the debug LED when a button is pressed. +*/ + +/** + @example change.ino + This example toggles the debug LED (pin 13) on or off when a button on pin 2 is pressed. +*/ + +/** + @example bounce_multiple.ino + Detect the falling edge of multiple buttons. Eight buttons with internal pullups. Toggles a LED when any button is pressed. Buttons on pins 2,3,4,5,6,7,8,9 +*/ + +/** + @example bounce2buttons.ino + Example of two instances of the Bounce class that switches the debug LED when either one of the two buttons is pressed. + */ + +static const uint8_t DEBOUNCED_STATE = 0b00000001; +static const uint8_t UNSTABLE_STATE = 0b00000010; +static const uint8_t CHANGED_STATE = 0b00000100; + +/** + The Bounce class. + */ +class Bounce +{ + public: + +/*! + @brief Create an instance of the Bounce class. + + @code + + // Create an instance of the Bounce class. + Bounce() button; + + @endcode +*/ + Bounce(); + + +/*! + @brief Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT). + + @param pin + The pin that is to be debounced. + @param mode + A valid Arduino pin mode (INPUT, INPUT_PULLUP or OUTPUT). +*/ + void attach(int pin, int mode); + + /** + Attach to a pin for advanced users. Only attach the pin this way once you have previously set it up. Otherwise use attach(int pin, int mode). + */ + void attach(int pin); + + /** + @brief Sets the debounce interval in milliseconds. + + @param interval_millis + The interval time in milliseconds. + + */ + void interval(uint16_t interval_millis); + + +/*! + @brief Updates the pin's state. + + Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your loop()). Only call update() once per loop(). + + @return True if the pin changed state. +*/ + + bool update(); + + /** + @brief Returns the pin's state (HIGH or LOW). + + @return HIGH or LOW. + */ + bool read(); + + /** + @brief Returns true if pin signal transitions from high to low. + */ + bool fell(); + + /** + @brief Returns true if pin signal transitions from low to high. + */ + bool rose(); + + + /** + @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 + */ + bool risingEdge() { return rose(); } + /** + @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 + */ + bool fallingEdge() { return fell(); } + /** + @brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1 + */ + Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() { + attach(pin); + interval(interval_millis); + } + + /** + @brief Returns the duration in milliseconds of the current state. + + Is reset to 0 once the pin rises ( rose() ) or falls ( fell() ). + + @return The duration in milliseconds (unsigned long) of the current state. + */ + + unsigned long duration(); + + /** + @brief Returns the duration in milliseconds of the previous state. + + Takes the values of duration() once the pin changes state. + + @return The duration in milliseconds (unsigned long) of the previous state. + */ + unsigned long previousDuration(); + + protected: + unsigned long previous_millis; + uint16_t interval_millis; + uint8_t state; + uint8_t pin; + unsigned long stateChangeLastTime; + unsigned long durationOfPreviousState; + virtual bool readCurrentState() { return digitalRead(pin); } + virtual void setPinMode(int pin, int mode) { +#if defined(ARDUINO_ARCH_STM32F1) + pinMode(pin, (WiringPinMode)mode); +#else + pinMode(pin, mode); +#endif + } + inline void changeState(); + inline void setStateFlag(const uint8_t flag) {state |= flag;} + inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;} + inline void toggleStateFlag(const uint8_t flag) {state ^= flag;} + inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);} + + public: + bool changed( ) { return getStateFlag(CHANGED_STATE); } + +}; + +#endif diff --git a/src/Bounce2Button.cpp b/src/Bounce2Button.cpp new file mode 100644 index 0000000..bf62489 --- /dev/null +++ b/src/Bounce2Button.cpp @@ -0,0 +1,15 @@ +#include "Bounce2Button.h" +bool BounceButton::read() +{ + return getStateFlag(DEBOUNCED_STATE) ^ invert; +} + +bool BounceButton::pressed() +{ + return (getStateFlag(DEBOUNCED_STATE) ^ invert) && getStateFlag(CHANGED_STATE); +} + +bool BounceButton::released() +{ + return !(getStateFlag(DEBOUNCED_STATE) ^ invert) && getStateFlag(CHANGED_STATE); +} diff --git a/src/Bounce2Button.h b/src/Bounce2Button.h new file mode 100644 index 0000000..82c651d --- /dev/null +++ b/src/Bounce2Button.h @@ -0,0 +1,19 @@ +#ifndef Bounce2Button_h +#define Bounce2Button_h + +#include "Bounce2.h" +class BounceButton : public Bounce{ + public: + BounceButton(){invert = false;} + + void setInvert(bool i){invert = i;} + + bool read(); + bool pressed(); + bool released(); + + protected: + bool invert; +}; + +#endif //Bounce2Button_h -- 2.54.0 From 3b9866e9e06da00b11e4103276a212a7d4a90ea7 Mon Sep 17 00:00:00 2001 From: NoobTracker <63962365+NoobTracker@users.noreply.github.com> Date: Fri, 8 May 2020 16:43:21 +0200 Subject: [PATCH 02/46] New keywords New keywords for setInvert(), pressed() and released(). --- keywords.txt | 67 ++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/keywords.txt b/keywords.txt index 3269e8f..437fba9 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,31 +1,36 @@ -####################################### -# Syntax Coloring Map For Bounce2 -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -Bounce KEYWORD1 -Bounce2 KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -update KEYWORD2 -interval KEYWORD2 -read KEYWORD2 -attach KEYWORD2 -rose KEYWORD2 -fell KEYWORD2 -duration KEYWORD2 - -####################################### -# Instances (KEYWORD2) -####################################### - -####################################### -# Constants (LITERAL1) -####################################### - +####################################### +# Syntax Coloring Map For Bounce2 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Bounce KEYWORD1 +Bounce2 KEYWORD1 +BounceButton KEYWORD1 +Bounce2Button KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +update KEYWORD2 +interval KEYWORD2 +read KEYWORD2 +attach KEYWORD2 +rose KEYWORD2 +fell KEYWORD2 +pressed KEYWORD2 +released KEYWORD2 +duration KEYWORD2 +setInvert KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### + -- 2.54.0 From 7e1cb95a9d289fd178b35f43ac9dd7a3b6ad1a5a Mon Sep 17 00:00:00 2001 From: NoobTracker <63962365+NoobTracker@users.noreply.github.com> Date: Fri, 8 May 2020 16:45:05 +0200 Subject: [PATCH 03/46] Example for Bounce2Button --- examples/Bounce2Button/Bounce2Button.ino | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/Bounce2Button/Bounce2Button.ino diff --git a/examples/Bounce2Button/Bounce2Button.ino b/examples/Bounce2Button/Bounce2Button.ino new file mode 100644 index 0000000..d5fea68 --- /dev/null +++ b/examples/Bounce2Button/Bounce2Button.ino @@ -0,0 +1,36 @@ + +// This example toggles the debug LED (pin 13) on or off +// when a button on pin 2 is pressed. + +// Include the Bounce2 library found here : +// https://github.com/thomasfredericks/Bounce2 +#include + +#define BUTTON_PIN 2 +#define LED_PIN 13 + +int ledState = LOW; + + +BounceButton debouncer = BounceButton(); // Instantiate a Bounce object + +void setup() { + + debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode + debouncer.interval(25); // Use a debounce interval of 25 milliseconds + debouncer.setInvert(true); + + pinMode(LED_PIN,OUTPUT); // Setup the LED + digitalWrite(LED_PIN,ledState); + +} + +void loop() { + + debouncer.update(); // Update the Bounce instance + + if ( debouncer.pressed() ) { // Call code if button transitions from HIGH to LOW + ledState = !ledState; // Toggle LED state + digitalWrite(LED_PIN,ledState); // Apply new LED state + } +} -- 2.54.0 From 1af864b0bd6b167a8b63380408ae85540fb117b3 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Tue, 19 May 2020 14:06:37 -0400 Subject: [PATCH 04/46] Added a Button class --- .../bounceMore.ino} | 0 .../bounceTwo.ino} | 0 examples/buttonClass/buttonClass.ino | 61 +++++++++++++++++++ keywords.txt | 6 +- src/Bounce2.h | 48 +++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) rename examples/{bounce_multiple/bounce_multiple.ino => bounceMore/bounceMore.ino} (100%) rename examples/{bounce2buttons/bounce2buttons.ino => bounceTwo/bounceTwo.ino} (100%) create mode 100644 examples/buttonClass/buttonClass.ino diff --git a/examples/bounce_multiple/bounce_multiple.ino b/examples/bounceMore/bounceMore.ino similarity index 100% rename from examples/bounce_multiple/bounce_multiple.ino rename to examples/bounceMore/bounceMore.ino diff --git a/examples/bounce2buttons/bounce2buttons.ino b/examples/bounceTwo/bounceTwo.ino similarity index 100% rename from examples/bounce2buttons/bounce2buttons.ino rename to examples/bounceTwo/bounceTwo.ino diff --git a/examples/buttonClass/buttonClass.ino b/examples/buttonClass/buttonClass.ino new file mode 100644 index 0000000..56d5a57 --- /dev/null +++ b/examples/buttonClass/buttonClass.ino @@ -0,0 +1,61 @@ + + + +/* + DESCRIPTION + ==================== + Simple example of the Button class from the Bounce library. + The Button class matches an electrical state to a physical action. + that switches the debug LED when + either of 2 buttons are pressed. + */ + +// Include the Bounce2 library found here : +// https://github.com/thomasfredericks/Bounce2 +#include + +#define BUTTON_PIN_A 2 +#define BUTTON_PIN_B 3 + + +#define LED_PIN 13 + +// Instantiate a Button object +Button buttonA = Button(); + +// Instantiate another Button object +Button buttonB = Button(); + +void setup() { + + // SETUP BUTTON A + buttonA.attach( BUTTON_PIN_A , INPUT_PULLUP ); + buttonA.interval(5); // interval in ms + buttonA.setPressedState(LOW); // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON + + // SETUP BUTTON B + buttonB.attach( BUTTON_PIN_B , INPUT_PULLUP ); + buttonB.interval(5); // interval in ms + buttonB.setPressedState(LOW); // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON + + + // SETUP LED + pinMode(LED_PIN,OUTPUT); + +} + +void loop() { + // UPDATE THE BUTTONS + buttonA.update(); + buttonB.update(); + + + // TURN ON LED IF EITHER BUTTON IS PRESSED + if ( buttonA.pressed() || buttonB.pressed() ) { + digitalWrite(LED_PIN, HIGH ); + } + else { + digitalWrite(LED_PIN, LOW ); + } + +} diff --git a/keywords.txt b/keywords.txt index 3269e8f..8f2c4de 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,7 +7,8 @@ ####################################### Bounce KEYWORD1 -Bounce2 KEYWORD1 +Bounce2 KEYWORD1 +Button KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -20,6 +21,9 @@ attach KEYWORD2 rose KEYWORD2 fell KEYWORD2 duration KEYWORD2 +pressed KEYWORD2 +released KEYWORD2 +setPressedState KEYWORD2 ####################################### # Instances (KEYWORD2) diff --git a/src/Bounce2.h b/src/Bounce2.h index d634890..c264b21 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -208,6 +208,54 @@ class Bounce public: bool changed( ) { return getStateFlag(CHANGED_STATE); } +}; + +/** + The Button class. + */ +class Button : public Bounce{ +protected: + bool stateForPressed = 0; +public: + /*! + @brief Create an instance of the Button class. + + @code + + // Create an instance of the Button class. + Button() button; + + @endcode +*/ + Button(){ } + + /*! + @brief Set the electrical state (HIGH/LOW) that corresponds to a physical press. + + @param state + The electrical state (HIGH/LOW) that corresponds to a physical press. + +*/ + void setPressedState(bool state){ + stateForPressed = state; + } + + /*! + @brief Returns true if the button was physically pressed +*/ + bool pressed() { + return changed() && (read() == stateForPressed); + }; + + /*! + @brief Returns true if the button was physically released +*/ + bool released() { + return changed() && (read() != stateForPressed); + }; + + + }; #endif -- 2.54.0 From 6147a340581546a4abc62aaaa3e5050dbd8a0ca9 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Thu, 21 May 2020 15:45:52 -0400 Subject: [PATCH 05/46] 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. -- 2.54.0 From 2b6be81dc1c5a86ddf1177f5e9c250dd89adc630 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Thu, 21 May 2020 16:03:08 -0400 Subject: [PATCH 06/46] Updated docs and version number --- docs/files/_bounce2_8h_source.html | 30 ++- docs/files/annotated.html | 1 + docs/files/bounce2buttons_8ino-example.html | 2 +- docs/files/bounce_8ino-example.html | 1 + docs/files/bounce_multiple_8ino-example.html | 2 +- docs/files/class_bounce-members.html | 21 +- docs/files/class_bounce.html | 40 ++- docs/files/class_bounce.png | Bin 0 -> 338 bytes docs/files/class_button-members.html | 103 ++++++++ docs/files/class_button.html | 256 +++++++++++++++++++ docs/files/class_button.png | Bin 0 -> 336 bytes docs/files/classes.html | 6 +- docs/files/functions.html | 15 ++ docs/files/functions_func.html | 15 ++ docs/files/hierarchy.html | 79 ++++++ docs/files/index.html | 2 +- docs/files/menudata.js | 1 + docs/files/search/all_1.js | 1 + docs/files/search/all_5.js | 5 +- docs/files/search/all_6.js | 5 +- docs/files/search/all_7.html | 26 ++ docs/files/search/all_7.js | 4 + docs/files/search/all_8.html | 26 ++ docs/files/search/all_8.js | 4 + docs/files/search/classes_0.js | 3 +- docs/files/search/functions_1.js | 3 +- docs/files/search/functions_5.js | 5 +- docs/files/search/functions_6.js | 5 +- docs/files/search/functions_7.html | 26 ++ docs/files/search/functions_7.js | 4 + docs/files/search/functions_8.html | 26 ++ docs/files/search/functions_8.js | 4 + docs/files/search/searchdata.js | 4 +- docs/files/tabs.css | 2 +- library.json | 2 +- library.properties | 2 +- 36 files changed, 688 insertions(+), 43 deletions(-) create mode 100644 docs/files/class_bounce.png create mode 100644 docs/files/class_button-members.html create mode 100644 docs/files/class_button.html create mode 100644 docs/files/class_button.png create mode 100644 docs/files/hierarchy.html create mode 100644 docs/files/search/all_7.html create mode 100644 docs/files/search/all_7.js create mode 100644 docs/files/search/all_8.html create mode 100644 docs/files/search/all_8.js create mode 100644 docs/files/search/functions_7.html create mode 100644 docs/files/search/functions_7.js create mode 100644 docs/files/search/functions_8.html create mode 100644 docs/files/search/functions_8.js diff --git a/docs/files/_bounce2_8h_source.html b/docs/files/_bounce2_8h_source.html index c8928ec..247b63f 100644 --- a/docs/files/_bounce2_8h_source.html +++ b/docs/files/_bounce2_8h_source.html @@ -66,18 +66,24 @@ $(function() {
Bounce2.h
-
1 /*
2  The MIT License (MIT)
3 
4  Copyright (c) 2013 thomasfredericks
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy of
7  this software and associated documentation files (the "Software"), to deal in
8  the Software without restriction, including without limitation the rights to
9  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10  the Software, and to permit persons to whom the Software is furnished to do so,
11  subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
25  Main code by Thomas O Fredericks (tof@t-o-f.info)
26  Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
27  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28 
29 #ifndef Bounce2_h
30 #define Bounce2_h
31 
32 #if defined(ARDUINO) && ARDUINO >= 100
33 #include "Arduino.h"
34 #else
35 #include "WProgram.h"
36 #endif
37 
38 // Uncomment the following line for "LOCK-OUT" debounce method
39 //#define BOUNCE_LOCK_OUT
40 
41 // Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
42 //#define BOUNCE_WITH_PROMPT_DETECTION
43 
44 #include <inttypes.h>
45 
69 class Bounce
70 {
71  public:
72 
83  Bounce();
84 
85 
95  void attach(int pin, int mode);
96 
100  void attach(int pin);
101 
102 
110  void interval(uint16_t interval_millis);
111 
112 
121  bool update();
122 
128  bool read();
129 
133  bool fell();
134 
138  bool rose();
139 
140 
144  bool risingEdge() { return rose(); }
148  bool fallingEdge() { return fell(); }
152  Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
153  attach(pin);
154  interval(interval_millis);
155  }
156 
165  unsigned long duration();
166 
167 
168  // WIP HELD : unsigned long held(); // Returns the duration the previous state was held
169 
170  protected:
171  unsigned long previous_millis;
172  uint16_t interval_millis;
173  uint8_t state;
174  uint8_t pin;
175  unsigned long stateChangeLastTime;
176  // WIP HELD : unsigned long durationOfPreviousState;
177  virtual bool readCurrentState() { return digitalRead(pin); }
178  virtual void setPinMode(int pin, int mode) {
179 #if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)
180  pinMode(pin, (WiringPinMode)mode);
181 #else
182  pinMode(pin, mode);
183 #endif
184  }
185 
186  private:
187  inline void changeState();
188  inline void setStateFlag(const uint8_t flag) {state |= flag;}
189  inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
190  inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
191  inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);}
192 };
193 
194 #endif
Definition: Bounce2.h:69
-
bool read()
Returns the pin&#39;s state (HIGH or LOW).
Definition: Bounce2.cpp:127
-
void interval(uint16_t interval_millis)
Sets the debounce interval in milliseconds.
Definition: Bounce2.cpp:36
-
bool fallingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:148
-
void attach(int pin, int mode)
Attach to a pin and sets that pin&#39;s mode (INPUT, INPUT_PULLUP or OUTPUT).
Definition: Bounce2.cpp:31
-
bool fell()
Returns true if pin signal transitions from high to low.
Definition: Bounce2.cpp:137
-
bool update()
Updates the pin&#39;s state.
Definition: Bounce2.cpp:41
-
bool risingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:144
-
unsigned long duration()
Returns the duration in milliseconds of the current state.
Definition: Bounce2.cpp:116
-
Bounce(uint8_t pin, unsigned long interval_millis)
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:152
-
Bounce()
Create an instance of the Bounce class.
Definition: Bounce2.cpp:11
-
bool rose()
Returns true if pin signal transitions from low to high.
Definition: Bounce2.cpp:132
+
1 /*
2  The MIT License (MIT)
3 
4  Copyright (c) 2013 thomasfredericks
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy of
7  this software and associated documentation files (the "Software"), to deal in
8  the Software without restriction, including without limitation the rights to
9  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10  the Software, and to permit persons to whom the Software is furnished to do so,
11  subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
25  Main code by Thomas O Fredericks (tof@t-o-f.info)
26  Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
27  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28 
35 #ifndef Bounce2_h
36 #define Bounce2_h
37 
38 #if defined(ARDUINO) && ARDUINO >= 100
39 #include "Arduino.h"
40 #else
41 #include "WProgram.h"
42 #endif
43 
44 // Uncomment the following line for "LOCK-OUT" debounce method
45 //#define BOUNCE_LOCK_OUT
46 
47 // Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
48 //#define BOUNCE_WITH_PROMPT_DETECTION
49 
50 #include <inttypes.h>
51 
72 static const uint8_t DEBOUNCED_STATE = 0b00000001;
73 static const uint8_t UNSTABLE_STATE = 0b00000010;
74 static const uint8_t CHANGED_STATE = 0b00000100;
75 
79 class Bounce
80 {
81  public:
82 
93  Bounce();
94 
95 
104  void attach(int pin, int mode);
105 
109  void attach(int pin);
110 
111 
119  void interval(uint16_t interval_millis);
120 
121 
130  bool update();
131 
137  bool read();
138 
142  bool fell();
143 
147  bool rose();
148 
149 
153  bool risingEdge() { return rose(); }
157  bool fallingEdge() { return fell(); }
161  Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
162  attach(pin);
163  interval(interval_millis);
164  }
165 
174  unsigned long duration();
175 
183  unsigned long previousDuration();
184 
185  protected:
186  unsigned long previous_millis;
187  uint16_t interval_millis;
188  uint8_t state;
189  uint8_t pin;
190  unsigned long stateChangeLastTime;
191  unsigned long durationOfPreviousState;
192  virtual bool readCurrentState() { return digitalRead(pin); }
193  virtual void setPinMode(int pin, int mode) {
194 #if defined(ARDUINO_ARCH_STM32F1)
195  pinMode(pin, (WiringPinMode)mode);
196 #else
197  pinMode(pin, mode);
198 #endif
199  }
200 
201  private:
202  inline void changeState();
203  inline void setStateFlag(const uint8_t flag) {state |= flag;}
204  inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
205  inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
206  inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);}
207 
208  public:
209  bool changed( ) { return getStateFlag(CHANGED_STATE); }
210 
211 };
212 
216 class Button : public Bounce{
217 protected:
218  bool stateForPressed = 1; //
219 public:
230  Button(){ }
231 
239  void setPressedState(bool state){
240  stateForPressed = state;
241  }
242 
246  bool pressed() {
247  return changed() && (read() == stateForPressed);
248  };
249 
253  bool released() {
254  return changed() && (read() != stateForPressed);
255  };
256 
257 
258 
259 };
260 
261 #endif
bool pressed()
Returns true if the button was physically pressed.
Definition: Bounce2.h:246
+
Definition: Bounce2.h:79
+
bool read()
Returns the pin&#39;s state (HIGH or LOW).
Definition: Bounce2.cpp:125
+
void interval(uint16_t interval_millis)
Sets the debounce interval in milliseconds.
Definition: Bounce2.cpp:34
+
bool released()
Returns true if the button was physically released.
Definition: Bounce2.h:253
+
unsigned long previousDuration()
Returns the duration in milliseconds of the previous state.
Definition: Bounce2.cpp:110
+
bool fallingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:157
+
void attach(int pin, int mode)
Attach to a pin and sets that pin&#39;s mode (INPUT, INPUT_PULLUP or OUTPUT).
Definition: Bounce2.cpp:29
+
bool fell()
Returns true if pin signal transitions from high to low.
Definition: Bounce2.cpp:135
+
bool update()
Updates the pin&#39;s state.
Definition: Bounce2.cpp:39
+
bool risingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:153
+
void setPressedState(bool state)
Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default, the pressed state is matched to a HIGH electrical level.
Definition: Bounce2.h:239
+
unsigned long duration()
Returns the duration in milliseconds of the current state.
Definition: Bounce2.cpp:114
+
Bounce(uint8_t pin, unsigned long interval_millis)
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:161
+
Definition: Bounce2.h:216
+
Bounce()
Create an instance of the Bounce class.
Definition: Bounce2.cpp:9
+
bool rose()
Returns true if pin signal transitions from low to high.
Definition: Bounce2.cpp:130
+
Button()
Create an instance of the Button class. By default, the pressed state is matched to a HIGH electrical...
Definition: Bounce2.h:230
diff --git a/docs/files/bounce2buttons_8ino-example.html b/docs/files/bounce2buttons_8ino-example.html index 1f7591d..7199c94 100644 --- a/docs/files/bounce2buttons_8ino-example.html +++ b/docs/files/bounce2buttons_8ino-example.html @@ -63,7 +63,7 @@ $(function() {

Example of two instances of the Bounce class that switches the debug LED when either one of the two buttons is pressed.

-
/*
DESCRIPTION
====================
Simple example of the Bounce library that switches the debug LED when
either of 2 buttons are pressed.
*/
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce2
#include <Bounce2.h>
#define BUTTON_PIN_1 2
#define BUTTON_PIN_2 3
#define LED_PIN 13
// Instantiate a Bounce object
Bounce debouncer1 = Bounce();
// Instantiate another Bounce object
Bounce debouncer2 = Bounce();
void setup() {
// Setup the first button with an internal pull-up :
pinMode(BUTTON_PIN_1,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer1.attach(BUTTON_PIN_1);
debouncer1.interval(5); // interval in ms
// Setup the second button with an internal pull-up :
pinMode(BUTTON_PIN_2,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer2.attach(BUTTON_PIN_2);
debouncer2.interval(5); // interval in ms
//Setup the LED :
pinMode(LED_PIN,OUTPUT);
}
void loop() {
// Update the Bounce instances :
debouncer1.update();
debouncer2.update();
// Get the updated value :
int value1 = debouncer1.read();
int value2 = debouncer2.read();
// Turn on the LED if either button is pressed :
if ( value1 == LOW || value2 == LOW ) {
digitalWrite(LED_PIN, HIGH );
}
else {
digitalWrite(LED_PIN, LOW );
}
}
+