Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <ToggleButton.h>
Public Member Functions | |
ToggleButton (uint8_t pin, bool pullup=true) | |
void | begin (bool startState=false, uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay) |
void | update () |
bool | on () |
PushButton which toggles state.
Push once - on. Push again - off.
Definition at line 9 of file ToggleButton.h.
ToggleButton::ToggleButton | ( | uint8_t | pin, |
bool | pullup = true |
||
) |
Constructor.
pin | the pin which he button is connected to. |
pullup | sets the logic type for the button. |
Note: if pullup is true the logic of the button is inverted - i.e. when the pin in pulled to ground, the button is considered to be pushed/on. The default is pullup, meaning that a LOW state on the pin means the button is on. Whilst this is a bit counter-intuitive, it is preferred as a floating pin will revert to off more readily than with non-pullup logic.
Definition at line 3 of file ToggleButton.cpp.
void ToggleButton::begin | ( | bool | startState = false , |
uint8_t | threshold = AbstractDebouncedButton::DefaultThreshold , |
||
uint8_t | delay = AbstractDebouncedButton::DefaultButtonDelay |
||
) |
Initialization.
startState | which state (on or off) the toggle starts in. |
threshold | how many tests of the pin must match for a press detection. |
delay | number of ms between tests of press detection. |
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 8 of file ToggleButton.cpp.
bool ToggleButton::on | ( | ) |
Test toggle state.
Definition at line 22 of file ToggleButton.cpp.
void ToggleButton::update | ( | ) |
Allocate Timeslice.
This method must be called frequently - usually from loop().
Definition at line 14 of file ToggleButton.cpp.