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
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.
10
9
11
-
## Installation
12
-
To use the **Button** library:
13
-
- Go to https://github.com/JChristensen/Button, click the **Download ZIP** button and save the ZIP file to a convenient location on your PC.
14
-
- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **Button-master**.
15
-
- Rename the folder to just **Button**.
16
-
- Copy the renamed folder to the Arduino sketchbook\libraries folder.
17
-
18
10
## Examples
19
11
The following example sketches are included with the **Button** library:
20
12
21
13
-**SimpleOnOff**: Just turns the Arduino's pin 13 LED on and off.
22
14
-**LongPress**: Demonstrates detecting long and short button presses.
23
15
-**UpDown**: Counts up or down, one number at a time or rapidly by holding the button down.
24
16
25
-
## Button library methods
17
+
## Button library functions
26
18
27
19
### Button(pin, puEnable, invert, dbTime)
28
20
##### Description
@@ -41,7 +33,7 @@ None.
41
33
Button myButton = Button(2, true, true, 25); //25 ms debounce
42
34
```
43
35
44
-
### read(void)
36
+
### read()
45
37
##### Description
46
38
Reads the button and returns a *boolean* value (*true* or *false*) to indicate whether the button is pressed. The read() function needs to execute very frequently in order for the sketch to be responsive. A good place for read() is at the top of loop(). Often, the return value from read() will not be needed if the other functions below are used.
47
39
##### Syntax
@@ -55,12 +47,12 @@ None.
55
47
myButton.read();
56
48
```
57
49
58
-
### isPressed(void)
59
-
### isReleased(void)
50
+
### isPressed()
51
+
### isReleased()
60
52
##### Description
61
53
These methods check the button state at the point in time when it was last read, and return false or true accordingly. These functions **do not** cause the button to be read.
62
54
##### Syntax
63
-
`myButton.isPressed();`
55
+
`myButton.isPressed();`
64
56
`myButton.isReleased();`
65
57
##### Parameters
66
58
None.
@@ -76,12 +68,12 @@ else {
76
68
}
77
69
```
78
70
79
-
### wasPressed(void)
80
-
### wasReleased(void)
71
+
### wasPressed()
72
+
### wasReleased()
81
73
##### Description
82
74
These methods check the button state to see if it changed between the last two reads and return false or true accordingly. These functions **do not** cause the button to be read. Note that these functions may be more useful than `isPressed()` and `isReleased()` since they actually detect a **change** in the state of the button, which is usually what we want in order to cause some action.
83
75
##### Syntax
84
-
`myButton.wasPressed();`
76
+
`myButton.wasPressed();`
85
77
`myButton.wasReleased();`
86
78
##### Parameters
87
79
None.
@@ -97,7 +89,7 @@ if ( myButton.wasPressed() ) { ...
97
89
##### Description
98
90
These methods check to see if the button is pressed (or released), and has been in that state for the specified time in milliseconds. Returns false or true accordingly. These functions are useful to detect "long presses". Note that these functions **do not** cause the button to be read.
99
91
##### Syntax
100
-
`myButton.pressedFor(ms);`
92
+
`myButton.pressedFor(ms);`
101
93
`myButton.releasedFor(ms);`
102
94
##### Parameters
103
95
**ms:** The number of milliseconds *(unsigned long)*
@@ -108,7 +100,7 @@ These methods check to see if the button is pressed (or released), and has been
108
100
if ( myButton.pressedFor(1000) ) { //has the button been pressed for one second?
109
101
```
110
102
111
-
### lastChange(void)
103
+
### lastChange()
112
104
##### Description
113
105
Under certain circumstances, it may be useful to know when a button last changed state. lastChange() returns the time the button last changed state, in milliseconds (the value is derived from the Arduino millis() function).
sentence=Arduino library to debounce button switches, detect presses, releases, and long presses.
6
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.
0 commit comments