AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Buttonable.ino
Go to the documentation of this file.
1/**
2 * @file Buttonable.ino Example on/off control from an Able button.
3 *
4 * This shows how Able can be used to create the same program as the built-in
5 * [Button example](https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button)
6 * included with the Arduino IDE.
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 * NB: This example uses direct pin reading which is not debounced. Contact
13 * bouncing can make the button's signal unstable for a few ms when pressed or
14 * released.
15 *
16 * @copyright Copyright (c) 2022 John Scott
17 */
18#include <AbleButtons.h>
19
20// Identify which buttons you are using...
21using Button = AblePullupDirectButton; ///< Using the direct pull-up button.
22using ButtonList = AblePullupDirectButtonList; ///< Using the direct pull-up button list.
23
24#define BUTTON_PIN 2 ///< Connect button between this pin and ground.
25Button btn(BUTTON_PIN); ///< The button to check.
26
27/**
28 * Setup the Buttonable example. Called once to initialise everything.
29 */
30void setup() {
31 btn.begin();
32 pinMode(LED_BUILTIN, OUTPUT);
33}
34
35/**
36 * Control the Buttonable example. Called repeatedly in a loop.
37 */
38void loop() {
39 btn.handle();
40
41 digitalWrite(LED_BUILTIN, btn.isPressed());
42}
The main include file for the Arduino Button library Extension (ABLE).
able::Button< able::PullupResistorCircuit, able::Pin > AblePullupDirectButton
AblePullupDirectButton provides basic button is-pressed capability for buttons connected using pull-u...
Definition: AbleButtons.h:215
able::ButtonList< AblePullupDirectButton > AblePullupDirectButtonList
AblePullupDirectButtonList allows an array of AblePullupDirectButton objects to be managed together.
Definition: AbleButtons.h:280
void setup()
Setup the Buttonable example.
Definition: Buttonable.ino:30
#define BUTTON_PIN
Connect button between this pin and ground.
Definition: Buttonable.ino:24
Button btn(BUTTON_PIN)
The button to check.
void loop()
Control the Buttonable example.
Definition: Buttonable.ino:38
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 isPressed() const
Determine if the button is currently pressed.
Definition: Button.h:103
Template for a list of buttons of the same type.
Definition: ButtonList.h:20