For ModulinoButtons and ModulinoEncoder (which provides a button), it would be very helpful to provide higher level API to detect clicks instead of having users implement their own state detection and debouncing logic.
Example of the desired API:
void loop() {
buttons.update();
if (buttons.wasClicked(0)) {
// button 0 was pressed and released
}
}
All the methods would return true only once after the state change, so that we don't get multiple triggers while the loop loops.
Maybe the basic .get(0) method could be renamed .isPressed(0) for clarity.
Bonus points:
- detection of double click (
.wasDoubleClicked(0))
- detection of simple state change (
.wasPressed(0), returning true only once after the state change + .wasReleased(0) as alias to .wasClicked(0))
- calculation of duration of press, useful to let users detect long presses (
duration = buttons.wasPressedFor(0))
See also
There are some very nice libraries for this. One of them is https://github.com/LennartHennigs/Button2
For ModulinoButtons and ModulinoEncoder (which provides a button), it would be very helpful to provide higher level API to detect clicks instead of having users implement their own state detection and debouncing logic.
Example of the desired API:
All the methods would return true only once after the state change, so that we don't get multiple triggers while the loop loops.
Maybe the basic
.get(0)method could be renamed.isPressed(0)for clarity.Bonus points:
.wasDoubleClicked(0)).wasPressed(0), returning true only once after the state change +.wasReleased(0)as alias to.wasClicked(0))duration = buttons.wasPressedFor(0))See also
There are some very nice libraries for this. One of them is https://github.com/LennartHennigs/Button2