From 50b796ccfcae7140de00514f58fdd6e5b66bc647 Mon Sep 17 00:00:00 2001 From: sseptillion Date: Tue, 8 Sep 2015 11:34:38 +0200 Subject: [PATCH 1/2] 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; -- 2.54.0 From 2d6327e91c0696c36e1cc479263e59f3756ae44b Mon Sep 17 00:00:00 2001 From: sseptillion Date: Tue, 8 Sep 2015 12:29:48 +0200 Subject: [PATCH 2/2] 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); -- 2.54.0