AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
DebouncableAny.ino
Go to the documentation of this file.
1/**
2 * @file DebouncableAny.ino Example toggle control from multiple buttons. If any
3 * button in the list is clicked, the built-in LED will toggle on/off.
4 *
5 * @copyright Copyright (c) 2022 John Scott
6 */
7#include <AbleButtons.h>
8
9// Identify which buttons you are using...
10using Button = AblePullupClickerButton; ///< Using clicker pull-up button.
11using ButtonList = AblePullupClickerButtonList; ///< Using clicker pull-up button list.
12
13#define BUTTON_A_PIN 2 ///< Connect button between this pin and ground.
14#define BUTTON_B_PIN 3 ///< Connect button between this pin and ground.
15
16Button btnA(BUTTON_A_PIN); ///< Primary button.
17Button btnB(BUTTON_B_PIN); ///< Secondary button.
18bool led = false; ///< On/off state of the LED.
19
20/// Array of buttons for ButtonList.
22 &btnA,
23 &btnB
24};
25ButtonList btnList(btns); ///< List of button to control together.
26
27/**
28 * Setup the DebouncableAny example. Called once to initialise everything.
29 */
30void setup() {
31 btnList.begin(); // ButtonList calls begin() for each button in the list.
32 pinMode(LED_BUILTIN, OUTPUT);
33}
34
35/**
36 * Control the DebouncableAny example. Called repeatedly in a loop.
37 */
38void loop() {
39 btnList.handle(); // ButtonList calls handle() for each button in the list.
40
41 // resetClicked() on ButtonList clears clicks on all the buttons in the list,
42 // returning if any one of the button was clicked. Resetting the clicks
43 // ensures clicks are handled only once.
44 if(btnList.resetClicked()) {
45 led = !led;
46 digitalWrite(LED_BUILTIN, led);
47 }
48}
The main include file for the Arduino Button library Extension (ABLE).
able::Button< able::PullupResistorCircuit, able::ClickerPin > AblePullupClickerButton
AblePullupClickerButton provides additional button-click capability to the is-pressed capability of a...
Definition: AbleButtons.h:193
able::ButtonList< AblePullupClickerButton > AblePullupClickerButtonList
AblePullupClickerButtonList allows an array of AblePullupClickerButton objects to be managed together...
Definition: AbleButtons.h:263
#define BUTTON_B_PIN
Connect button between this pin and ground.
Button * btns[]
Array of buttons for ButtonList.
ButtonList btnList(btns)
List of button to control together.
void setup()
Setup the DebouncableAny example.
Button btnA(BUTTON_A_PIN)
Primary button.
Button btnB(BUTTON_B_PIN)
Secondary button.
#define BUTTON_A_PIN
Connect button between this pin and ground.
bool led
On/off state of the LED.
void loop()
Control the DebouncableAny example.
Core Button class.
Definition: Button.h:22
Template for a list of buttons of the same type.
Definition: ButtonList.h:20
void handle()
Handle all the buttons.
Definition: ButtonList.h:63
bool resetClicked()
Reset clicked state of all buttons, returning true if any were clicked.
Definition: ButtonList.h:74
void begin()
Initialise all the buttons.
Definition: ButtonList.h:53