AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Buttonable2.ino
Go to the documentation of this file.
1/**
2 * @file Buttonable2.ino Example on/off control from a button. Similar to the
3 * Buttonable example, except this example uses a debounced pin.
4 *
5 * NB: All that's changes is the `using Button` and `using ButtonList` lines at
6 * the beginning of the program to select debounced reading capability.
7 *
8 * The built-in LED lights when a button connected between pin 2 and ground is
9 * pressed. It uses the internal pull-up resistor within an Arduino for the
10 * simplest button connection.
11 *
12 * @copyright Copyright (c) 2022 John Scott
13 */
14#include <AbleButtons.h>
15
16// Identify which buttons you are using...
17using Button = AblePullupButton; ///< Using basic pull-up button.
18using ButtonList = AblePullupButtonList; ///< Using basic pull-up button list.
19
20#define BUTTON_PIN 2 ///< Connect button between this pin and ground.
21Button btn(BUTTON_PIN); ///< The button to check.
22
23/**
24 * Setup the Buttonable2 example. Called once to initialise everything.
25 */
26void setup() {
27 btn.begin();
28 pinMode(LED_BUILTIN, OUTPUT);
29}
30
31/**
32 * Control the Buttonable2 example. Called repeatedly in a loop.
33 */
34void loop() {
35 btn.handle();
36
37 digitalWrite(LED_BUILTIN, btn.isPressed());
38}
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
void setup()
Setup the Buttonable2 example.
Definition: Buttonable2.ino:26
#define BUTTON_PIN
Connect button between this pin and ground.
Definition: Buttonable2.ino:20
Button btn(BUTTON_PIN)
The button to check.
void loop()
Control the Buttonable2 example.
Definition: Buttonable2.ino:34
Core Button class.
Definition: Button.h:22
void begin()
Initialise the button.
Definition: Button.h:60
void handle()
Handle the button.
Definition: Button.h:67
bool isPressed() const
Determine if the button is currently pressed.
Definition: Button.h:127
Template for a list of buttons of the same type.
Definition: ButtonList.h:20