diff --git a/examples/bounce/bounce.ino b/examples/bounce/bounce.ino index 139620d..2c75bda 100644 --- a/examples/bounce/bounce.ino +++ b/examples/bounce/bounce.ino @@ -5,7 +5,7 @@ Simple example of the Bounce library that switches the debug LED when a button is pressed. */ // Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce-Arduino-Wiring +// https://github.com/thomasfredericks/Bounce2 #include #define BUTTON_PIN 2 diff --git a/examples/bounce_multiple/bounce_multiple.ino b/examples/bounce_multiple/bounce_multiple.ino new file mode 100644 index 0000000..25b92c7 --- /dev/null +++ b/examples/bounce_multiple/bounce_multiple.ino @@ -0,0 +1,56 @@ +// 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 + +// Include the Bounce2 library found here : +// https://github.com/thomasfredericks/Bounce2 +#include + +#define LED_PIN 13 + +#define NUM_BUTTONS 8 +const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9}; + +int ledState = LOW; + +Bounce * buttons = new Bounce[NUM_BUTTONS]; + +void setup() { + + for (int i = 0; i < NUM_BUTTONS; i++) { + buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP ); //setup the bounce instance for the current button + buttons[i].interval(25); // interval in ms + } + + // Setup the LED : + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, ledState); + + +} + +void loop() { + + bool needToToggleLed = false; + + + for (int i = 0; i < NUM_BUTTONS; i++) { + // Update the Bounce instance : + buttons[i].update(); + // If it fell, flag the need to toggle the LED + if ( buttons[i].fell() ) { + needToToggleLed = true; + } + } + + // if a LED toggle has been flagged : + if ( needToToggleLed ) { + // Toggle LED state : + ledState = !ledState; + digitalWrite(LED_PIN, ledState); + } + + +} + diff --git a/examples/change/change.ino b/examples/change/change.ino index eb5fa26..0ece35b 100644 --- a/examples/change/change.ino +++ b/examples/change/change.ino @@ -2,7 +2,7 @@ // Detect the falling edge // Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce-Arduino-Wiring +// https://github.com/thomasfredericks/Bounce2 #include diff --git a/examples/duration/duration.ino b/examples/duration/duration.ino index f0abcc5..f3189ad 100644 --- a/examples/duration/duration.ino +++ b/examples/duration/duration.ino @@ -7,7 +7,7 @@ a button press (transition from HIGH to LOW). */ // Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce-Arduino-Wiring +// https://github.com/thomasfredericks/Bounce2 #include diff --git a/examples/retrigger/retrigger.ino b/examples/retrigger/retrigger.ino index b1143ee..dfc53fd 100644 --- a/examples/retrigger/retrigger.ino +++ b/examples/retrigger/retrigger.ino @@ -9,7 +9,7 @@ Open the Serial Monitor (57600 baud) for debug messages. */ // Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce-Arduino-Wiring +// https://github.com/thomasfredericks/Bounce2 #include