AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
ButtonableAll.ino
Go to the documentation of this file.
1/**
2 * @file ButtonableAll.ino Example on/off control from multiple buttons. Only
3 * when all the button in the list are pressed will the built-in LED lights.
4 * Each button is connected to a subsequent pin.
5 *
6 * @copyright Copyright (c) 2022 John Scott
7 */
8#include <AbleButtons.h>
9
10// Identify which buttons you are using...
11using Button = AblePullupButton; ///< Using basic pull-up button.
12using ButtonList = AblePullupButtonList; ///< Using basic pull-up button list.
13
14#define BUTTON_A_PIN 2 ///< Connect button between this pin and ground.
15#define BUTTON_B_PIN 3 ///< Connect button between this pin and ground.
16
17Button btnA(BUTTON_A_PIN); ///< Primary button.
18Button btnB(BUTTON_B_PIN); ///< Secondary button.
19
20/// Array of buttons for ButtonList.
21Button *btns[] = {
22 &btnA,
23 &btnB
24};
25ButtonList btnList(btns); ///< List of button to control together.
26
27/**
28 * Setup the ButtonableAll 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 ButtonableAll example. Called repeatedly in a loop.
37 */
38void loop() {
39 btnList.handle(); // ButtonList calls handle() for each button in the list.
40
41 if(btnList.allPressed()) { // ButtonList can check all buttons together.
42 digitalWrite(LED_BUILTIN, HIGH);
43 } else {
44 digitalWrite(LED_BUILTIN, LOW);
45 }
46}
The main include file for the Arduino Button library Extension (ABLE).
able::ButtonList< AblePullupButton > AblePullupButtonList
Handler for list of AblePullupButton objects.
Definition: AbleButtons.h:245
able::Button< able::PullupResistorCircuit, able::DebouncedPin > AblePullupButton
AblePullupButton provides basic button is-pressed capability for buttons connected using pull-up resi...
Definition: AbleButtons.h:175
#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 ButtonableAll 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.
void loop()
Control the ButtonableAll 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 allPressed() const
Determine if all of the buttons are currently pressed.
Definition: ButtonList.h:138
void begin()
Initialise all the buttons.
Definition: ButtonList.h:53