From 7ed666b7b19c42f58043da8d51401bbd1c0e95c6 Mon Sep 17 00:00:00 2001 From: thomasfredericks Date: Wed, 6 May 2015 11:05:29 -0400 Subject: [PATCH 1/4] Added a 2 button example --- examples/bounce2buttons/bounce2buttons.ino | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 examples/bounce2buttons/bounce2buttons.ino diff --git a/examples/bounce2buttons/bounce2buttons.ino b/examples/bounce2buttons/bounce2buttons.ino new file mode 100644 index 0000000..416d738 --- /dev/null +++ b/examples/bounce2buttons/bounce2buttons.ino @@ -0,0 +1,64 @@ + +/* + 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 + +#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 ); + } + +} + + From ea7731102f11fdcdc02d78f3ec9be7030818a7f8 Mon Sep 17 00:00:00 2001 From: thomasfredericks Date: Fri, 24 Jul 2015 08:43:05 -0400 Subject: [PATCH 2/4] Added library properties --- library.properties | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 library.properties diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..8236f51 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=Bounce2 +version=2.1 +author=Thomas O Fredericks with contributions fromEric Lowry, Jim Schimpf and Tom Harkaway +maintainer=Thomas O Fredericks +sentence=Debouncing library for Arduino and Wiring. +paragraph=Deboucing switches and toggles is important. +category=Signal Input/Output +url=https://github.com/thomasfredericks/Bounce2 +architectures=* \ No newline at end of file From 50b796ccfcae7140de00514f58fdd6e5b66bc647 Mon Sep 17 00:00:00 2001 From: sseptillion Date: Tue, 8 Sep 2015 11:34:38 +0200 Subject: [PATCH 3/4] Added pinMode setting to attach Added possibility to attach the pin and auto set the pinMode. Attach and pinMode can now be done in 1 step. just call Bounce.attach(pin, INPUT_PULLUP) etc --- Bounce2.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Bounce2.cpp b/Bounce2.cpp index afbcac7..b5265ee 100644 --- a/Bounce2.cpp +++ b/Bounce2.cpp @@ -33,6 +33,17 @@ void Bounce::attach(int pin) { #endif } +void Bounce::attach(int pin, byte mode){ + if(mode == INPUT_PULLUP){ + pinMode(pin, INPUT_PULLUP); + } + else{ + pinMode(pin, INPUT); + } + + this->attach(pin); +} + void Bounce::interval(uint16_t interval_millis) { this->interval_millis = interval_millis; From 2d6327e91c0696c36e1cc479263e59f3756ae44b Mon Sep 17 00:00:00 2001 From: sseptillion Date: Tue, 8 Sep 2015 12:29:48 +0200 Subject: [PATCH 4/4] Added pinMode setting to attach Added possibility to attach the pin and auto set the pinMode. Attach and pinMode can now be done in 1 step. just call Bounce.attach(pin, INPUT_PULLUP) etc Fixed Header file and made all mode possible. --- Bounce2.cpp | 9 ++------- Bounce2.h | 3 +++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Bounce2.cpp b/Bounce2.cpp index b5265ee..c947815 100644 --- a/Bounce2.cpp +++ b/Bounce2.cpp @@ -33,13 +33,8 @@ void Bounce::attach(int pin) { #endif } -void Bounce::attach(int pin, byte mode){ - if(mode == INPUT_PULLUP){ - pinMode(pin, INPUT_PULLUP); - } - else{ - pinMode(pin, INPUT); - } +void Bounce::attach(int pin, int mode){ + pinMode(pin, mode); this->attach(pin); } diff --git a/Bounce2.h b/Bounce2.h index 2d44f7c..77d384d 100644 --- a/Bounce2.h +++ b/Bounce2.h @@ -47,6 +47,9 @@ class Bounce // Attach to a pin (and also sets initial state) void attach(int pin); + + // Attach to a pin (and also sets initial state) and sets pin to mode (INPUT/INPUT_PULLUP/OUTPUT) + void attach(int pin, int mode); // Sets the debounce interval void interval(uint16_t interval_millis);