-
Notifications
You must be signed in to change notification settings - Fork 4
Buttons
Buttons need to be debounced, detected and repeated.
(Key for transitions: red=button/switch action, blue=timeout, green=app action)
The state machine is fairly simple, and has two time-based transitions: one during debounce where a button has to be held for a certain amount of time before it counts as a press, and once read and still held, it re-registers as a press after a period for repeat. The timeouts are driven off the display refresh/millisecond interrupt.
There are two repeat timeouts: the initial one (delay before repeat) and each subsequent repeat. When the switch goes from closed→latched (ie, first pressed) the timeout is set to REPT_INIT. Once the button has been sampled, the repeat timeout starts. When it triggers and the state goes from sampled→latched, the next repeat timeout is set to REPT_RATE.
