diff --git a/button_demoReel100/jsbutton.h b/button_demoReel100/jsbutton.h index 0576d32..926bbf0 100644 --- a/button_demoReel100/jsbutton.h +++ b/button_demoReel100/jsbutton.h @@ -16,7 +16,6 @@ * */ - //================================================= // MULTI-CLICK: One Button, Multiple Events @@ -25,7 +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 - // Button variables boolean buttonVal = HIGH; // value read from button boolean buttonLast = HIGH; // buffered value of the button's previous state @@ -37,12 +35,20 @@ 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). +*/ 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) {