AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
DoublableCallback.ino
Go to the documentation of this file.
1/**
2 * @file DoublableCallback.ino Example of toggling an LED using callback
3 * functions instead of a clicker. When the button is single-clicked, the LED
4 * will be illuminated. Double-click to turn the LED off.
5 *
6 * @copyright Copyright (c) 2024 John Scott
7 */
8#include <AbleButtons.h>
9
10// Identify which buttons you are using...
11using Button = AblePullupCallbackDoubleClickerButton; ///< Using callback pull-up button.
12using ButtonList = AblePullupCallbackDoubleClickerButtonList; ///< Using callback pull-up button list.
13
14// Forward declaration of callback function.
15void clickedCallback(Button::CALLBACK_EVENT, uint8_t);
16
17#define BUTTON_PIN 2 ///< Connect button between this pin and ground.
18Button btn(BUTTON_PIN, clickedCallback); ///< The button to check.
19bool led = false; ///< On/off state of the LED.
20
21/**
22 * Setup the ClickedBtn example. Called once to initialise everything.
23 */
24void setup() {
25 btn.begin();
26 pinMode(LED_BUILTIN, OUTPUT);
27}
28
29/**
30 * Control the ClickedBtn example. Called repeatedly in a loop.
31 */
32void loop() {
33 btn.handle();
34}
35
36/**
37 * Callback function for button released.
38 *
39 * @param event The event that has occured.
40 * @param id The identifier of the button generating the callback (ignored in this example).
41 */
42void clickedCallback(Button::CALLBACK_EVENT event, uint8_t id) {
43 (void)id; // id is unused.
44
45 if(event == Button::SINGLE_CLICKED_EVENT) {
46 led = false;
47 digitalWrite(LED_BUILTIN, led);
48 } else if(event == Button::DOUBLE_CLICKED_EVENT) {
49 led = true;
50 digitalWrite(LED_BUILTIN, led);
51 }
52}
The main include file for the Arduino Button library Extension (ABLE).
able::ButtonList< AblePullupCallbackDoubleClickerButton > AblePullupCallbackDoubleClickerButtonList
AblePullupCallbackDoubleClickerButtonList allows an array of AblePullupCallbackDoubleClickerButton ob...
Definition: AbleButtons.h:298
able::CallbackClickerButton< able::CallbackButton< able::Button< able::PullupResistorCircuit, able::DoubleClickerPin > > > AblePullupCallbackDoubleClickerButton
AblePullupCallbackDoubleClickerButton provides additional double-click capability to the is-clicked c...
Definition: AbleButtons.h:233
void setup()
Setup the ClickedBtn example.
Button btn(BUTTON_PIN, clickedCallback)
The button to check.
void clickedCallback(Button::CALLBACK_EVENT, uint8_t)
Callback function for button released.
#define BUTTON_PIN
Connect button between this pin and ground.
bool led
On/off state of the LED.
void loop()
Control the ClickedBtn example.
Core Button class.
Definition: Button.h:22
void begin()
Initialise the button.
Definition: Button.h:60
void handle()
Handle the button.
Definition: Button.h:67
Template for a list of buttons of the same type.
Definition: ButtonList.h:20