Add isPressed function to support latching switch.
Closed this issue · 1 comments
alw1746 commented
Support latching switch usage with isPressed function:
In OneButton.h,
bool isPressed() const { return _state == OCS_DOWN; }
In loop(),
button.tick();
if (button.isPressed()) { //switch latched on
if (!ledOn) {
digitalWrite(LED_BUILTIN,HIGH);
ledOn=true;
}
}
else if (button.isIdle()) { //latch released
if (ledOn) {
digitalWrite(LED_BUILTIN,LOW);
ledOn=false;
}
}
mathertel commented
You can use the public isIdle() function for this:
if (! button.isIdle()) {
// on
} else {
// off
}