Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <MultiThrowSwitch.h>
Public Member Functions | |
MultiThrowSwitch (uint8_t throws, const uint8_t pins[], bool sticky=false, bool pullup=true) | |
void | begin (int startPosition=0, uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay) |
void | update () |
uint8_t | position () |
For modelling things like rotary dials which can have one (or none) of a group of pins active at a given time, with a numeric position between 1 and the number of throws for the position of the switch.
Definition at line 13 of file MultiThrowSwitch.h.
MultiThrowSwitch::MultiThrowSwitch | ( | uint8_t | throws, |
const uint8_t | pins[], | ||
bool | sticky = false , |
||
bool | pullup = true |
||
) |
Constructor.
throws | the number of throws (pins) for the switch. |
pins | an array of pins (must be "throws" long). \patam sticky if true, stay with the last active position until a new position is active. If false then the position is 0 if no pins are active. |
pullup | sets the logic type for the various pins. |
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 5 of file MultiThrowSwitch.cpp.
void MultiThrowSwitch::begin | ( | int | startPosition = 0 , |
uint8_t | threshold = AbstractDebouncedButton::DefaultThreshold , |
||
uint8_t | delay = AbstractDebouncedButton::DefaultButtonDelay |
||
) |
Initialization.
startPosition | which position is active at start (0 means automatic) |
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 40 of file MultiThrowSwitch.cpp.
uint8_t MultiThrowSwitch::position | ( | ) |
Get switch position.
Definition at line 76 of file MultiThrowSwitch.cpp.
void MultiThrowSwitch::update | ( | ) |
Allocate Timeslice.
This method must be called frequently - usually from loop().
Definition at line 53 of file MultiThrowSwitch.cpp.