|
Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
Timeslice-based button with debouncing using analogRead. More...
#include <DebouncedAnalogButton.h>

Public Member Functions | |
| DebouncedAnalogButton (const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512) | |
| 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 AnalogInputButton | |
| AnalogInputButton (const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512) | |
| void | begin () |
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 AnalogInputButton | |
| const uint8_t | _pin |
| const bool | _pullup |
| const uint16_t | _analogThreshold |
Timeslice-based button with debouncing using analogRead.
DebouncedAnalogButton reduces / eliminates bouncing (multiple press events registing close together with only one physical press).
This class reads from the pin using analogRead. This is occasionally useful when special analog-only pins need to be used for button inputs (e.g. pins A6 and A7 on the nano).
Definition at line 16 of file DebouncedAnalogButton.h.
| DebouncedAnalogButton::DebouncedAnalogButton | ( | const uint8_t | pin, |
| const bool | pullup = true, |
||
| const uint16_t | analogThreshold = 512 |
||
| ) |
Constructor.
| pin | the pin used for this button. |
| pullup | if true pin==LOW means on, else pin==HIGH is on. |
| analogThreshold | the value mid way between the on and off states as reported by analogRead. |
Definition at line 5 of file DebouncedAnalogButton.cpp.
| void DebouncedAnalogButton::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 10 of file DebouncedAnalogButton.cpp.

|
virtual |
Test instantaneous input state (with debouncing)
Reimplemented from AnalogInputButton.
Definition at line 31 of file DebouncedAnalogButton.cpp.
|
virtual |
Allocate Timeslice
This method must be called frequently - usually from loop()
Implements AbstractDebouncedButton.
Definition at line 16 of file DebouncedAnalogButton.cpp.

1.8.15