AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
ButtonableCallback.ino
Go to the documentation of this file.
1/**
2 * @file ButtonableCallback.ino Example on/off button via callback functions.
3 * Similar to Buttonable example, but uses on-pressed and on-released callback
4 * functions to control the built-in LED.
5 *
6 * @copyright Copyright (c) 2022 John Scott
7 */
8#include <AbleButtons.h>
9
10// Identify which buttons you are using...
11using Button = AblePullupCallbackButton; ///< Using callback pull-up button.
12using ButtonList = AblePullupCallbackButtonList; ///< Using callback pull-up button list.
13
14// Declarations of callback functions defined later.
16
17#define BUTTON_PIN 2 ///< Connect button between this pin and ground.
18Button btn(BUTTON_PIN, buttonableCallback); ///< The button to check.
19
20/**
21 * Setup the ButtonableCallback example. Called once to initialise everything.
22 */
23void setup() {
24 btn.begin();
25 pinMode(LED_BUILTIN, OUTPUT);
26}
27
28/**
29 * Control the ButtonableCallback example. Called repeatedly in a loop.
30 */
31void loop() {
32 btn.handle();
33}
34
35/**
36 * Callback function for button events.
37 *
38 * @param event The event that has occured.
39 * @param id The identifier of the button generating the callback (unused in
40 * this example).
41 */
43 (void)id; // id is unused.
44
45 if(event == Button::PRESSED_EVENT) {
46 digitalWrite(LED_BUILTIN, HIGH);
47 } else {
48 digitalWrite(LED_BUILTIN, LOW);
49 }
50}
The main include file for the Arduino Button library Extension (ABLE).
able::ButtonList< AblePullupCallbackButton > AblePullupCallbackButtonList
AblePullupCallbackButtonList allows an array of AblePullupCallbackButton objects to be managed togeth...
Definition: AbleButtons.h:254
able::CallbackButton< able::Button< able::PullupResistorCircuit, able::DebouncedPin > > AblePullupCallbackButton
Shorthand for a callback button using a pulldown resistor.
Definition: AbleButtons.h:185
void setup()
Setup the ButtonableCallback example.
Button btn(BUTTON_PIN, buttonableCallback)
The button to check.
#define BUTTON_PIN
Connect button between this pin and ground.
void buttonableCallback(Button::CALLBACK_EVENT, uint8_t)
Callback function for button events.
void loop()
Control the ButtonableCallback example.
Core Button class.
Definition: Button.h:22
void begin()
Initialise the button.
Definition: Button.h:51
void handle()
Handle the button.
Definition: Button.h:58
Template for a list of buttons of the same type.
Definition: ButtonList.h:20
CALLBACK_EVENT
Button event codes.
@ PRESSED_EVENT
The button has been pressed.