From 9ca9cf21473817fbb9eb616f8943ff861e7cc91d Mon Sep 17 00:00:00 2001 From: t0mekk / Tomek Kubas Date: Tue, 6 Mar 2018 11:17:33 +0100 Subject: [PATCH 1/2] invert logic added ability to invert logic / useful when using Arduino Nano --- button_demoReel100/jsbutton.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/button_demoReel100/jsbutton.h b/button_demoReel100/jsbutton.h index 0576d32..9a042ac 100644 --- a/button_demoReel100/jsbutton.h +++ b/button_demoReel100/jsbutton.h @@ -16,7 +16,6 @@ * */ - //================================================= // MULTI-CLICK: One Button, Multiple Events @@ -25,6 +24,13 @@ int debounce = 20; // ms debounce period to prevent flickering when pre int DCgap = 250; // max ms between clicks for a double click event int holdTime = 1000; // ms hold period: how long to wait for press+hold event +int invert = 1; // invert true/false + +/* +invert If invert == 0, interprets a high state as pressed, low as + * released. If invert != 0, interprets a high state as + * released, low as pressed (can also use true or false). +*/ // Button variables boolean buttonVal = HIGH; // value read from button @@ -40,9 +46,11 @@ boolean holdEventPast = false; // whether or not the hold event happened alre + uint8_t checkButton() { uint8_t event = 0; buttonVal = digitalRead(buttonPin); + if (invert !=0) buttonVal = !buttonVal; // invert logic // Button pressed down if (buttonVal == LOW && buttonLast == HIGH && (millis() - upTime) > debounce) { From 9e2396c7b50a2a1cdaa0c26750cecaa2f6a54c38 Mon Sep 17 00:00:00 2001 From: t0mekk / Tomek Kubas Date: Tue, 6 Mar 2018 11:20:53 +0100 Subject: [PATCH 2/2] cleanup --- button_demoReel100/jsbutton.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/button_demoReel100/jsbutton.h b/button_demoReel100/jsbutton.h index 9a042ac..926bbf0 100644 --- a/button_demoReel100/jsbutton.h +++ b/button_demoReel100/jsbutton.h @@ -24,14 +24,6 @@ int debounce = 20; // ms debounce period to prevent flickering when pre int DCgap = 250; // max ms between clicks for a double click event int holdTime = 1000; // ms hold period: how long to wait for press+hold event -int invert = 1; // invert true/false - -/* -invert If invert == 0, interprets a high state as pressed, low as - * released. If invert != 0, interprets a high state as - * released, low as pressed (can also use true or false). -*/ - // Button variables boolean buttonVal = HIGH; // value read from button boolean buttonLast = HIGH; // buffered value of the button's previous state @@ -43,7 +35,13 @@ long upTime = -1; // time the button was released boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered boolean waitForUp = false; // when held, whether to wait for the up event boolean holdEventPast = false; // whether or not the hold event happened already +int invert = 1; // invert true/false +/* +invert If invert == 0, interprets a high state as pressed, low as + * released. If invert != 0, interprets a high state as + * released, low as pressed (can also use true or false). +*/