Skip to content

Invert logic for button control #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions button_demoReel100/jsbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
*/


//=================================================
// MULTI-CLICK: One Button, Multiple Events

Expand All @@ -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
Expand All @@ -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)
{
Expand Down