AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Doublable.ino
Go to the documentation of this file.
1/**
2 * @file Doublable.ino Example toggle control from an Able button.
3 *
4 * The built-in LED toggles on/off when a button connected between pin 2 and
5 * ground is double-clicked. It uses the internal pull-up resistor within an
6 * Arduino for the simplest button connection.
7 *
8 * @copyright Copyright (c) 2022 John Scott
9 */
10#include <AbleButtons.h>
11
12// Identify which buttons you are using...
13using Button = AblePullupDoubleClickerButton; ///< Using double-clicker pull-up button.
14using ButtonList = AblePullupDoubleClickerButtonList; ///< Using double-clicker pull-up button list.
15
16#define BUTTON_PIN 2 ///< Connect button between this pin and ground.
17Button btn(BUTTON_PIN); ///< The button to check.
18bool led = false; ///< On/off state of the LED.
19
20/**
21 * Setup the Debouncable example. Called once to initialise everything.
22 */
23void setup() {
24 btn.begin();
25 pinMode(LED_BUILTIN, OUTPUT);
26}
27
28/**
29 * Control the Debouncable example. Called repeatedly in a loop.
30 */
31void loop() {
32 btn.handle();
33
34 // resetDoubleClicked() clears the double-click, returning if the button was
35 // double-clicked. It resets the double-click, so it only returns true once
36 // per double-click.
38 led = !led;
39 digitalWrite(LED_BUILTIN, led);
40 }
41}
The main include file for the Arduino Button library Extension (ABLE).
able::ButtonList< AblePullupDoubleClickerButton > AblePullupDoubleClickerButtonList
AblePullupDoubleClickerButtonList allows an array of AblePullupDoubleClickerButton objects to be mana...
Definition: AbleButtons.h:289
able::Button< able::PullupResistorCircuit, able::DoubleClickerPin > AblePullupDoubleClickerButton
AblePullupDoubleClickerButton provides additional double-click capability to the is-clicked capabilit...
Definition: AbleButtons.h:224
void setup()
Setup the Debouncable example.
Definition: Doublable.ino:23
#define BUTTON_PIN
Connect button between this pin and ground.
Definition: Doublable.ino:16
bool led
On/off state of the LED.
Definition: Doublable.ino:18
Button btn(BUTTON_PIN)
The button to check.
void loop()
Control the Debouncable example.
Definition: Doublable.ino:31
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 resetDoubleClicked()
Reset the double-clicked state of the button, returning what is was.
Definition: Button.h:111
Template for a list of buttons of the same type.
Definition: ButtonList.h:20