AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Holdable.ino
Go to the documentation of this file.
1/**
2 * @file Holdable.ino Example button hold control from an Able button.
3 *
4 * The built-in LED lights up when a button connected between pin 2 and
5 * ground is held down for 2 seconds or more. It uses the internal pull-up
6 * resistor within an 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 = AblePullupButton; ///< Using basic pull-up button.
14using ButtonList = AblePullupButtonList; ///< Using basic 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.
18
19/**
20 * Setup the Debouncable example. Called once to initialise everything.
21 */
22void setup() {
23 pinMode(LED_BUILTIN, OUTPUT);
24
25 Button::setHeldTime(2000);
26 Button::setIdleTime(10000);
27
28 btn.begin();
29}
30
31/**
32 * Control the Debouncable example. Called repeatedly in a loop.
33 */
34void loop() {
35 btn.handle();
36
37 digitalWrite(LED_BUILTIN, btn.isHeld());
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 Debouncable example.
Definition: Holdable.ino:22
#define BUTTON_PIN
Connect button between this pin and ground.
Definition: Holdable.ino:16
Button btn(BUTTON_PIN)
The button to check.
void loop()
Control the Debouncable example.
Definition: Holdable.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 isHeld() const
Determine if the button is currently held down.
Definition: Button.h:136
Template for a list of buttons of the same type.
Definition: ButtonList.h:20