AbleButtons
V0.4.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...
11
using
Button
=
AblePullupCallbackButton
;
///< Using callback pull-up button.
12
using
ButtonList
=
AblePullupCallbackButtonList
;
///< Using callback pull-up button list.
13
14
// Declarations of callback functions defined later.
15
void
buttonableCallback
(
Button::CALLBACK_EVENT
, uint8_t);
16
17
#define BUTTON_PIN 2
///< Connect button between this pin and ground.
18
Button
btn
(
BUTTON_PIN
,
buttonableCallback
);
///< The button to check.
19
20
/**
21
* Setup the ButtonableCallback example. Called once to initialise everything.
22
*/
23
void
setup
() {
24
btn
.
begin
();
25
pinMode(LED_BUILTIN, OUTPUT);
26
}
27
28
/**
29
* Control the ButtonableCallback example. Called repeatedly in a loop.
30
*/
31
void
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
*/
42
void
buttonableCallback
(
Button::CALLBACK_EVENT
event, uint8_t
id
) {
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
}
AbleButtons.h
The main include file for the Arduino Button library Extension (ABLE).
AblePullupCallbackButtonList
able::ButtonList< AblePullupCallbackButton > AblePullupCallbackButtonList
AblePullupCallbackButtonList allows an array of AblePullupCallbackButton objects to be managed togeth...
Definition:
AbleButtons.h:254
AblePullupCallbackButton
able::CallbackButton< able::Button< able::PullupResistorCircuit, able::DebouncedPin > > AblePullupCallbackButton
Shorthand for a callback button using a pulldown resistor.
Definition:
AbleButtons.h:185
setup
void setup()
Setup the ButtonableCallback example.
Definition:
ButtonableCallback.ino:23
btn
Button btn(BUTTON_PIN, buttonableCallback)
The button to check.
BUTTON_PIN
#define BUTTON_PIN
Connect button between this pin and ground.
Definition:
ButtonableCallback.ino:17
buttonableCallback
void buttonableCallback(Button::CALLBACK_EVENT, uint8_t)
Callback function for button events.
Definition:
ButtonableCallback.ino:42
loop
void loop()
Control the ButtonableCallback example.
Definition:
ButtonableCallback.ino:31
able::Button
Core Button class.
Definition:
Button.h:22
able::Button::begin
void begin()
Initialise the button.
Definition:
Button.h:60
able::Button::handle
void handle()
Handle the button.
Definition:
Button.h:67
able::ButtonList
Template for a list of buttons of the same type.
Definition:
ButtonList.h:20
able::CallbackButton::CALLBACK_EVENT
CALLBACK_EVENT
Button event codes.
Definition:
CallbackButton.h:24
able::CallbackButton::PRESSED_EVENT
@ PRESSED_EVENT
The button has been pressed.
Definition:
CallbackButton.h:26
AbleButtons
examples
ButtonableCallback
ButtonableCallback.ino
Generated by
1.9.5