Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <AbstractDebouncedButton.h>
Public Member Functions | |
AbstractDebouncedButton () | |
void | begin (uint8_t threshold=DefaultThreshold, uint8_t delay=DefaultButtonDelay) |
virtual void | update ()=0 |
bool | pushed (bool peek=false) |
uint32_t | tapped (bool peek=false) |
bool | held (uint16_t ms=DefaultHeldMs) |
bool | repeat (uint16_t initialMs=DefaultButtonRepeatInitialMs, uint16_t repeatMs=DefaultButtonRepeatMs) |
void | setState (bool newState) |
Public Member Functions inherited from AbstractButton | |
AbstractButton () | |
virtual void | begin () |
virtual bool | on ()=0 |
Timeslice-based button with debouncing.
AbstractDebouncedButton reduces / eliminates bouncing (multiple press events registing close together with only one physical press).
Definition at line 11 of file AbstractDebouncedButton.h.
AbstractDebouncedButton::AbstractDebouncedButton | ( | ) |
Constructor.
Definition at line 6 of file AbstractDebouncedButton.cpp.
void AbstractDebouncedButton::begin | ( | uint8_t | threshold = DefaultThreshold , |
uint8_t | delay = DefaultButtonDelay |
||
) |
Initialization.
threshold | how many tests of the pin must match for a state change. |
delay | number of ms between tests of pin state. |
Should be called from setup(), or at any rate, before other members are called. This will set the pinMode. The minimum time it takes for button presses / released to register is threshold * delay.
Definition at line 10 of file AbstractDebouncedButton.cpp.
bool AbstractDebouncedButton::held | ( | uint16_t | ms = DefaultHeldMs | ) |
Test if held on for extended period.
ms | time in ms the button has to have been on for to be considered held |
Definition at line 34 of file AbstractDebouncedButton.cpp.
bool AbstractDebouncedButton::pushed | ( | bool | peek = false | ) |
Test if the button has been pushed since the last time it was off.
This function returns true once, as soon as the button is pushed - even if it has not been released yet. If the peek parameter is false then subsequent calls to pushed will not return true until the button has been released and pushed again. The idea is to allow frequent tests in a tight loop, and only get one positive result (unlike on(), which returns true any time the button is depressed).
peek | if true, do not reset the pushed state. |
Definition at line 20 of file AbstractDebouncedButton.cpp.
bool AbstractDebouncedButton::repeat | ( | uint16_t | initialMs = DefaultButtonRepeatInitialMs , |
uint16_t | repeatMs = DefaultButtonRepeatMs |
||
) |
Get periodic press results when button is held.
initialMs | time between first press and first repeat in ms. |
repeatMs | time between subsequent releats. |
Definition at line 39 of file AbstractDebouncedButton.cpp.
void AbstractDebouncedButton::setState | ( | bool | newState | ) |
Explicitly set the state of the button.
newState | the new state to have. |
Definition at line 58 of file AbstractDebouncedButton.cpp.
uint32_t AbstractDebouncedButton::tapped | ( | bool | peek = false | ) |
Test if the button has been pushed and released.
After returning a non-zero value (i.e. a tap was registered), the state will be reset. Only the last tap duration will be returned.
peek | if true, do not reset the pushed state. |
Definition at line 27 of file AbstractDebouncedButton.cpp.
|
pure virtual |
Allocate timeslice.
This method must be called frequently - usually from loop().
Implemented in DebouncedButton, DebouncedAnalogButton, and DebouncedDualButton.