Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <DualButton.h>
Public Member Functions | |
DualButton (DebouncedButton *b1, DebouncedButton *b2) | |
void | begin (uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay) |
void | update () |
bool | on () |
bool | pushed () |
bool | tapped () |
bool | held (uint16_t ms=AbstractDebouncedButton::DefaultHeldMs) |
bool | repeat (uint16_t initialMs=AbstractDebouncedButton::DefaultButtonRepeatInitialMs, uint16_t repeatMs=AbstractDebouncedButton::DefaultButtonRepeatMs) |
Single button object responding to two inputs
DualButton acts like a single button, but will respond to input from one of two separate DebouncedButtons on different pins and potentially with different pin logic. This makes it easy to have a second input (e.g. wired button and FM button) whilst maintaining the clean syntax of a single button object in your sketch.
Definition at line 20 of file DualButton.h.
DualButton::DualButton | ( | DebouncedButton * | b1, |
DebouncedButton * | b2 | ||
) |
Constructor
b1 | A pointer to a DebouncedButton object |
v2 | A pointer to a DebouncedButton object |
Definition at line 3 of file DualButton.cpp.
void DualButton::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 call the begin() method in both of the linked DebouncedButtons.
Definition at line 9 of file DualButton.cpp.
bool DualButton::held | ( | uint16_t | ms = AbstractDebouncedButton::DefaultHeldMs | ) |
Test if either button is held on for extended period
ms | time in ms the button has to have been on for to be considered held |
Definition at line 36 of file DualButton.cpp.
bool DualButton::on | ( | ) |
Test instantaneous input state (with debouncing)
Definition at line 21 of file DualButton.cpp.
bool DualButton::pushed | ( | ) |
Test if either button has been pushed since the last time it was off.
The idea is that you can called pushed lots of times ina tight loop and only get one true return pre press of the button regardless of how many times you test.
Definition at line 26 of file DualButton.cpp.
bool DualButton::repeat | ( | uint16_t | initialMs = AbstractDebouncedButton::DefaultButtonRepeatInitialMs , |
uint16_t | repeatMs = AbstractDebouncedButton::DefaultButtonRepeatMs |
||
) |
Get periodic press results when either button is held.
initialMs | time between first press and first repeat in ms |
repeatMs | time between subsequent releats |
Definition at line 41 of file DualButton.cpp.
bool DualButton::tapped | ( | ) |
Test if either button has been pushed and released.
Definition at line 31 of file DualButton.cpp.
void DualButton::update | ( | ) |
Allocate Timeslice
This method must be called frequently - usually from loop()
Definition at line 15 of file DualButton.cpp.