Callback button template to call a function if the button is pressed.
More...
#include <CallbackButton.h>
|
static uint8_t | nextId () |
| Return the next auto-assigned button identifier. More...
|
|
template<typename
Button>
class able::CallbackButton< Button >
Callback button template to call a function if the button is pressed.
- Parameters
-
Button | The base button class for Callback. Defaults to the Button template class. |
Definition at line 18 of file CallbackButton.h.
◆ CALLBACK_EVENT
Button event codes.
When a callback function is called, the first argument is an event code below.
Enumerator |
---|
BEGIN_EVENT | The button's begin() method has completed.
|
PRESSED_EVENT | The button has been pressed.
|
RELEASED_EVENT | The button has been released.
|
HELD_EVENT | The button has been held down for a while.
|
IDLE_EVENT | The button has been idle (untouched) for a while.
|
Definition at line 24 of file CallbackButton.h.
◆ CallbackButton()
Create a callback button on the specified pin.
- Parameters
-
pin | The pin connected to the button. |
callbackFn | The function to call when the button is pressed. |
id | Callback identifier for the button (default auto-assigned). |
Definition at line 44 of file CallbackButton.h.
◆ begin()
◆ handle()
◆ id()
Return the id of the button.
- Returns
- The id of the button (auto-assigned or set when created).
Definition at line 117 of file CallbackButton.h.
◆ isClicked()
Determine if the button is clicked.
Clicks are registered as a press then release. If the ClickerPin (or subclass) is used, the button returns the click state, otherwise the compile will fail with errors.
- Returns
- True if clicked else false.
Definition at line 132 of file Button.h.
◆ isDoubleClicked()
Determine if the button is double-clicked.
Double-clicks are registered as two clicks within the double-click time. If the DoubleClickPin is used, the button returns the double-click state, otherwise the compile will fail with errors.
- Returns
- True if double-clicked else false.
Definition at line 144 of file Button.h.
◆ isHeld()
Determine if the button is currently held down.
- Returns
- True if held, else false.
Definition at line 112 of file Button.h.
◆ isIdle()
Determine if the button is currently idle (unpressed for a "long" time).
- Returns
- True if idle, else false.
Definition at line 121 of file Button.h.
◆ isPressed()
Determine if the button is currently pressed.
- Returns
- True if pressed, else false.
Definition at line 103 of file Button.h.
◆ nextId()
static uint8_t able::Pin::nextId |
( |
| ) |
|
|
inlinestaticprotectedinherited |
Return the next auto-assigned button identifier.
- Returns
- The next auto-assigned button identifier. Each call increases the auto-assigned identifier.
Definition at line 29 of file Pins.h.
◆ readPin()
void able::Pin::readPin |
( |
| ) |
|
|
inlineprotectedinherited |
Read the pin directly.
In order to save memory, virtual functions are not used (which can consume almost 1K of memory to deal with). Runtime polymorphism is not required, so avoiding virtual functions saves memory.
Definition at line 62 of file Pins.h.
◆ resetClicked()
Reset the clicked state of the button, returning what is was.
This allows the click state to be effectively read once so that a clicked state only triggers something once, when checked. For example toggling something on/off when the button is clicked. For buttons that don't support clicking, the compile will fail with errors.
- Returns
- True if the button was clicked, else false.
Definition at line 71 of file Button.h.
◆ resetDoubleClicked()
Reset the double-clicked state of the button, returning what is was.
This allows the double-click state to be effectively read once so that a double-clicked state only triggers something once, when checked. For example toggling something on/off when the button is double- clicked. For buttons that don't support double-clicking, the compile will fail with errors.
- Returns
- True if the button was double-clicked, else false.
Definition at line 87 of file Button.h.
◆ setCallback()
Set a (new) callback function.
- Parameters
-
callbackFn | The function to call for a button event. Use 0 to clear the callback function. |
Definition at line 103 of file CallbackButton.h.
◆ autoId_
uint8_t able::Pin::autoId_ = 0 |
|
staticprotectedinherited |
Auto-assigned button identifier.
Definition at line 70 of file Pins.h.
◆ callbackFn_
◆ currState_
uint8_t able::Pin::currState_ |
|
protectedinherited |
The reading of the pin.
Definition at line 73 of file Pins.h.
◆ id_
Identifier for the button passed to callback functions.
Definition at line 126 of file CallbackButton.h.
◆ longEvent_
◆ pin_
The Arduino pin connected to the button.
Definition at line 72 of file Pins.h.
The documentation for this class was generated from the following file: