Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <DebouncedButton.h>
Public Member Functions | |
DebouncedButton (uint8_t pin, bool pullup=true) | |
virtual | ~DebouncedButton () |
void | begin (uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay) |
void | update () |
bool | on () |
Public Member Functions inherited from AbstractDebouncedButton | |
AbstractDebouncedButton () | |
void | begin (uint8_t threshold=DefaultThreshold, uint8_t delay=DefaultButtonDelay) |
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 () | |
Public Member Functions inherited from DigitalInputButton | |
DigitalInputButton (const uint8_t pin, const bool pullup=true) | |
void | begin () |
bool | on () |
Additional Inherited Members | |
Static Public Attributes inherited from AbstractDebouncedButton | |
static const uint8_t | DefaultThreshold = 5 |
static const uint8_t | DefaultButtonDelay = 5 |
static const uint16_t | DefaultHeldMs = 800 |
static const uint16_t | DefaultButtonRepeatInitialMs = 700 |
static const uint16_t | DefaultButtonRepeatMs = 350 |
Protected Attributes inherited from AbstractDebouncedButton | |
uint8_t | _threshold |
uint8_t | _delay |
uint32_t | _lastUpdate |
uint8_t | _counter |
bool | _state |
uint32_t | _lastStateChange |
bool | _pushed |
uint16_t | _repeatCount |
uint32_t | _lastRepeat |
uint32_t | _lastOnDuration |
Protected Attributes inherited from DigitalInputButton | |
const uint8_t | _pin |
const bool | _pullup |
Timeslice-based button with debouncing
DebouncedButton reduces / eliminates bouncing (multiple press events registing close together with only one physical press).
The update() method must be called frequently (usually from loop()) to work properly.
Definition at line 15 of file DebouncedButton.h.
DebouncedButton::DebouncedButton | ( | uint8_t | pin, |
bool | pullup = true |
||
) |
Constructor.
pin | the pin used for this button. |
pullup | if true pin==LOW means on, else pin==HIGH is on. |
Definition at line 6 of file DebouncedButton.cpp.
|
inlinevirtual |
Destructor
Must have this to derive from DebouncedButton without warnings.
Definition at line 28 of file DebouncedButton.h.
void DebouncedButton::begin | ( | uint8_t | threshold = AbstractDebouncedButton::DefaultThreshold , |
uint8_t | delay = AbstractDebouncedButton::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 11 of file DebouncedButton.cpp.
|
virtual |
Test instantaneous input state (with debouncing).
Implements AbstractButton.
Definition at line 31 of file DebouncedButton.cpp.
|
virtual |
Allocate timeslice.
This method must be called frequently - usually from loop().
Implements AbstractDebouncedButton.
Definition at line 17 of file DebouncedButton.cpp.