AbleButtons
V0.4.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...
11
using
Button
=
AblePullupButton
;
///< Using basic pull-up button.
12
using
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
17
Button
btnA
(
BUTTON_A_PIN
);
///< Primary button.
18
Button
btnB
(
BUTTON_B_PIN
);
///< Secondary button.
19
20
/// Array of buttons for ButtonList.
21
Button
*
btns
[] = {
22
&
btnA
,
23
&
btnB
24
};
25
ButtonList
btnList
(
btns
);
///< List of button to control together.
26
27
/**
28
* Setup the ButtonableAll example. Called once to initialise everything.
29
*/
30
void
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
*/
38
void
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
}
AbleButtons.h
The main include file for the Arduino Button library Extension (ABLE).
AblePullupButtonList
able::ButtonList< AblePullupButton > AblePullupButtonList
Handler for list of AblePullupButton objects.
Definition:
AbleButtons.h:245
AblePullupButton
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
BUTTON_B_PIN
#define BUTTON_B_PIN
Connect button between this pin and ground.
Definition:
ButtonableAll.ino:15
btns
Button * btns[]
Array of buttons for ButtonList.
Definition:
ButtonableAll.ino:21
btnList
ButtonList btnList(btns)
List of button to control together.
setup
void setup()
Setup the ButtonableAll example.
Definition:
ButtonableAll.ino:30
btnA
Button btnA(BUTTON_A_PIN)
Primary button.
btnB
Button btnB(BUTTON_B_PIN)
Secondary button.
BUTTON_A_PIN
#define BUTTON_A_PIN
Connect button between this pin and ground.
Definition:
ButtonableAll.ino:14
loop
void loop()
Control the ButtonableAll example.
Definition:
ButtonableAll.ino:38
able::Button
Core Button class.
Definition:
Button.h:22
able::ButtonList
Template for a list of buttons of the same type.
Definition:
ButtonList.h:20
able::ButtonList::handle
void handle()
Handle all the buttons.
Definition:
ButtonList.h:63
able::ButtonList::allPressed
bool allPressed() const
Determine if all of the buttons are currently pressed.
Definition:
ButtonList.h:154
able::ButtonList::begin
void begin()
Initialise all the buttons.
Definition:
ButtonList.h:53
AbleButtons
examples
ButtonableAll
ButtonableAll.ino
Generated by
1.9.5