AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Debouncable.ino
Go to the documentation of this file.
1/**
2 * @file Debouncable.ino Example toggle control from an Able button.
3 *
4 * This shows how Able can be used to create the same program as the built-in
5 * [Debounce example](https://www.arduino.cc/en/Tutorial/BuiltInExamples/Debounce)
6 * included with the Arduino IDE.
7 *
8 * The built-in LED toggles on/off when a button connected between pin 2 and
9 * ground is clicked (pressed, then released). It uses the internal pull-up
10 * resistor within an Arduino for the 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 = AblePullupClickerButton; ///< Using clicker pull-up button.
18using ButtonList = AblePullupClickerButtonList; ///< Using clicker 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.
22bool led = false; ///< On/off state of the LED.
23
24/**
25 * Setup the Debouncable example. Called once to initialise everything.
26 */
27void setup() {
28 btn.begin();
29 pinMode(LED_BUILTIN, OUTPUT);
30}
31
32/**
33 * Control the Debouncable example. Called repeatedly in a loop.
34 */
35void loop() {
36 btn.handle();
37
38 // resetClicked() clears the click, returning if the button was clicked. It
39 // resets the click, so it only returns true once per click.
40 if(btn.resetClicked()) {
41 led = !led;
42 digitalWrite(LED_BUILTIN, led);
43 }
44}
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
void setup()
Setup the Debouncable example.
Definition: Debouncable.ino:27
#define BUTTON_PIN
Connect button between this pin and ground.
Definition: Debouncable.ino:20
bool led
On/off state of the LED.
Definition: Debouncable.ino:22
Button btn(BUTTON_PIN)
The button to check.
void loop()
Control the Debouncable example.
Definition: Debouncable.ino:35
Core Button class.
Definition: Button.h:22
void begin()
Initialise the button.
Definition: Button.h:51
void handle()
Handle the button.
Definition: Button.h:58
bool resetClicked()
Reset the clicked state of the button, returning what is was.
Definition: Button.h:71
Template for a list of buttons of the same type.
Definition: ButtonList.h:20