You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arduino Button Library Copyright (C) 2018 Jack Christensen GNU GPL v3.0
6
+
Arduino Button Library Copyright (C) 2018-2019 Jack Christensen GNU GPL v3.0
7
7
8
8
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0 as published by the Free Software Foundation.
9
9
@@ -16,14 +16,18 @@ The Button library is for debouncing and reading momentary contact switches like
16
16
17
17
The simplest way to use a button with an AVR microcontroller is to wire the button between a GPIO pin and ground, and turn on the AVR internal pullup resistor. The Button class constructor takes four arguments, but three have default values that work for a button wired in this manner.
18
18
19
+
A derived class, ToggleButton, implements button objects that need only "push-on, push-off" functionality.
20
+
19
21
## Examples
20
22
The following example sketches are included with the **Button** library:
21
23
22
24
-**SimpleOnOff**: Just turns the Arduino's pin 13 LED on and off.
23
25
-**LongPress**: Demonstrates detecting long and short button presses.
24
26
-**UpDown**: Counts up or down, one number at a time or rapidly by holding the button down.
The constructor defines a toggle button object, which has "push-on, push-off" functionality. The initial state can be on or off. See the section, [ToggleButton Library Functions](https://github.com/JChristensen/JC_Button#togglebutton-library-functions) for functions that apply specifically to the ToggleButton object. The ToggleButton class is derived from the Button class, so all Button functions are available, but because it is inherently a more limited concept, the special ToggleButton functions will be most useful, along with `begin()` and `read()`.
**pin:** Arduino pin number that the button is connected to *(byte)*
65
+
##### Optional parameters
66
+
**initialState:** Initial state for the button. Defaults to off (false) if not given. *(bool)*
67
+
**dbTime:** Debounce time in milliseconds. Defaults to 25ms if not given. *(unsigned long)*
68
+
**puEnable:** *true* to enable the microcontroller's internal pull-up resistor, else *false*. Defaults to *true* if not given. *(bool)*
69
+
**invert:** *false* interprets a high logic level to mean the button is pressed, *true* interprets a low level as pressed. *true* should be used when a pull-up resistor is employed, *false* for a pull-down resistor. Defaults to *true* if not given. *(bool)*
70
+
##### Returns
71
+
None.
72
+
##### Example
73
+
```c++
74
+
// button connected from pin 2 to ground, initial state off,
75
+
// 25ms debounce, pullup enabled, logic inverted
76
+
ToggleButton myToggle(2);
77
+
78
+
// same as above but this button is initially "on" and also
79
+
// needs a longer debounce time (50ms).
80
+
ToggleButton myToggle(3, true, 50);
81
+
82
+
// a button wired from the MCU pin to Vcc with an external pull-down resistor,
83
+
// initial state is off.
84
+
Button myButton(4, false, 25, false, false);
85
+
86
+
```
87
+
88
+
## Button Library Functions
54
89
55
90
### begin()
56
91
##### Description
@@ -73,7 +108,7 @@ Reads the button and returns a *boolean* value (*true* or *false*) to indicate w
73
108
##### Parameters
74
109
None.
75
110
##### Returns
76
-
*true* if the button is pressed, *else*false *(bool)*
111
+
*true* if the button is pressed, else*false**(bool)*
77
112
##### Example
78
113
```c++
79
114
myButton.read();
@@ -153,3 +188,47 @@ The time in milliseconds when the button last changed state *(unsigned long)*
sentence=Arduino library to debounce button switches, detect presses, releases, and long presses.
6
-
paragraph=The Button library is for debouncing and reading momentary contact switches like tactile button switches. "Long presses" of arbitrary length can be detected. Works well in state machine constructs. Use the read() function to read each button in the main loop, which should execute as fast as possible.
6
+
paragraph=Copyright (C) 2018-2019 by Jack Christensen and licensed under GNU GPL v3.0.
0 commit comments