Skip to content

Commit 279b142

Browse files
committed
minor documentation changes
1 parent 3362edb commit 279b142

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.DS_Store
2-
.idea/
2+
.idea/

README.md

+59-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
11
Arduino OneButton Library
22
===
33

4-
This Arduino libary is improving the usage of a singe button for input.
4+
This Arduino library is improving the usage of a singe button for input.
55
It shows how to use an digital input pin with a single pushbutton attached
66
for detecting some of the typical button press events like single clicks, double clicks and long-time pressing.
77
This enables you to reuse the same button for multiple functions and lowers the hardware investments.
88

99
This is also a sample for implementing simple finite-state machines by using the simple pattern above.
1010

11-
You can find more detail on this library at
11+
You can find more details on this library at
1212
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
1313

14+
1415
## Getting Started
1516

1617
Clone this repository into `Arduino/Libraries` or use the built-in Arduino IDE Library manager to install
1718
a copy of this library. You can find more detail about installing libraries
1819
[here, on Arduino's website](https://www.arduino.cc/en/guide/libraries).
1920

20-
```c++
21+
```CPP
2122
#include <Arduino.h>
2223
#include <OneButton.h>
2324
```
2425

25-
### Initialize a Button
26-
2726
Each physical button requires its own `OneButton` instance. You can initialize them like this:
2827

29-
```c++
28+
29+
### Initialize a Button to GND
30+
31+
```CPP
32+
#define BUTTON_PIN 4
33+
34+
/**
35+
* Initialize a new OneButton instance for a button
36+
* connected to digital pin 4 and GND, which is active low
37+
* and uses the internal pull-up resistor.
38+
*/
39+
40+
OneButton btn = OneButton(
41+
BUTTON_PIN, // Input pin for the button
42+
LOW, // Button is active LOW
43+
true // Enable internal pull-up resistor
44+
);
45+
```
46+
47+
48+
### Initialize a Button to VCC
49+
50+
```CPP
3051
#define BUTTON_PIN 4
3152

3253
/**
3354
* Initialize a new OneButton instance for a button
34-
* connected to digital pin 4, which is active high,
35-
* and does not use the internal pull-up resistors.
55+
* connected to digital pin 4, which is active high.
56+
* As this does not use any internal resistor
57+
* an external resistor (4.7k) may be required to create a LOW signal when the button is not pressed.
3658
*/
3759

3860
OneButton btn = OneButton(
@@ -42,12 +64,13 @@ OneButton btn = OneButton(
4264
);
4365
```
4466

67+
4568
### Attach State Events
4669

4770
Once you have your button initialized, you can handle events by attaching them to the button
4871
instance. Events can either be static functions or lambdas (without captured variables).
4972

50-
```c++
73+
```CPP
5174
// Handler function for a single click:
5275
static void handleClick() {
5376
Serial.println("Clicked!");
@@ -62,31 +85,34 @@ btn.attachDoubleClick([]() {
6285
});
6386
```
6487

88+
6589
### Don't forget to `tick()`!
6690

6791
In order for `OneButton` to work correctly, you must call `tick()` on __each button instance__
6892
within your main `loop()`. If you're not getting any button events, this is probably why.
6993

70-
```c++
94+
```CPP
7195
void loop() {
7296
btn.tick();
7397

7498
// Do other things...
7599
}
76100
```
77101

102+
78103
## State Events
79104

80105
Here's a full list of events handled by this library:
81106

82-
|Attach Function|Description|
83-
|---|---|
84-
|`attachClick`|Fires as soon as a single click is detected.|
85-
|`attachDoubleClick`|Fires as soon as a double click is detected.|
86-
|`attachPressStart`|Fires as soon as the button is pressed down.|
87-
|`attachLongPressStart`|Fires as soon as the button is held down for 1 second.|
88-
|`attachDuringLongPress`|Fires periodically as long as the button is held down.|
89-
|`attachLongPressStop`|Fires when the button is released after a long hold.|
107+
| Attach Function | Description |
108+
| ----------------------- | ------------------------------------------------------ |
109+
| `attachClick` | Fires as soon as a single click is detected. |
110+
| `attachDoubleClick` | Fires as soon as a double click is detected. |
111+
| `attachPressStart` | Fires as soon as the button is pressed down. |
112+
| `attachLongPressStart` | Fires as soon as the button is held down for 1 second. |
113+
| `attachDuringLongPress` | Fires periodically as long as the button is held down. |
114+
| `attachLongPressStop` | Fires when the button is released after a long hold. |
115+
90116

91117
### Event Timing
92118

@@ -97,30 +123,34 @@ the following functions to change the timing.
97123
click event is not attached, the library will assume a valid single click after one click duration,
98124
otherwise it must wait for the double click timeout to pass.
99125

100-
|Function|Default (ms)|Description|
101-
|---|---|---|
102-
|`setDebounceTicks(int)`|`50`|Period of time in which to ignore additional level changes.|
103-
|`setClickTicks(int)`|`600`|Timeout used to distinguish single clicks from double clicks.|
104-
|`setPressTicks(int)`|`1000`|Duration to hold a button to trigger a long press.|
126+
| Function | Default (ms) | Description |
127+
| ----------------------- | ------------ | ------------------------------------------------------------- |
128+
| `setDebounceTicks(int)` | `50` | Period of time in which to ignore additional level changes. |
129+
| `setClickTicks(int)` | `600` | Timeout used to distinguish single clicks from double clicks. |
130+
| `setPressTicks(int)` | `1000` | Duration to hold a button to trigger a long press. |
131+
105132

106133
### Additional Functions
107134

108135
`OneButton` also provides a couple additional functions to use for querying button status:
109136

110-
|Function|Description|
111-
|---|---|
112-
|`bool isLongPressed()`|Detect whether or not the button is currently inside a long press.|
113-
|`int getPressedTicks()`|Get the current number of milliseconds that the button has been held down for.|
137+
| Function | Description |
138+
| ----------------------- | ------------------------------------------------------------------------------ |
139+
| `bool isLongPressed()` | Detect whether or not the button is currently inside a long press. |
140+
| `int getPressedTicks()` | Get the current number of milliseconds that the button has been held down for. |
141+
114142

115143
### `tick()` and `reset()`
116144

117145
You can specify a logic level when calling `tick(bool)`, which will skip reading the pin and use
118146
that level instead. If you wish to reset the internal state of your buttons, call `reset()`.
119147

148+
120149
## Troubleshooting
121150

122151
If your buttons aren't acting they way they should, check these items:
123152

124153
1. Check your wiring and pin numbers.
125-
1. Did you call `tick()` on each button instance in your loop?
126-
1. Did you alter your clock timers in any way without adjusting ticks?
154+
2. Did you call `tick()` on each button instance in your loop?
155+
3. Did you alter your clock timers in any way without adjusting ticks?
156+

0 commit comments

Comments
 (0)