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
[](https://github.com/ArminJo/EasyButtonAtInt01/commits/master)

15
+
<br/>
16
+
<br/>
17
+
[](https://stand-with-ukraine.pp.ua)
18
+
19
+
Available as [Arduino library "EasyButtonAtInt01"](https://www.arduinolibraries.info/libraries/easy-button-at-int01).
3
20
4
-
### [Version 3.3.2](https://github.com/ArminJo/EasyButtonAtInt01/releases) - work in progress
[](https://github.com/ArminJo/EasyButtonAtInt01/commits/master)
Available as [Arduino library "EasyButtonAtInt01"](https://www.arduinolibraries.info/libraries/easy-button-at-int01).
27
+
#### If you find this library useful, please give it a star.
28
+
29
+
<br/>
13
30
14
31
# Features
15
32
- No external pullup, **no polling needed**.
@@ -97,7 +114,7 @@ void loop() {}
97
114
```
98
115
99
116
## Long press detection
100
-
The easiest way is to check it in the button release handler. Do not forget, that you will get a press callback (if enabled) at the start of the long press.
117
+
The easiest way is to use the button release handler. Keep in mind, that you will get a press callback at the start of the long press.
101
118
102
119
```c++
103
120
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
EasyButton Button0AtPin2(&handleButtonPress); // Button is connected to INT0 (pin2)
147
+
148
+
void setup() {}
149
+
void loop() {
150
+
if (!sLongPressMessageSent && Button0AtPin2.checkForLongPress(1000) == EASY_BUTTON_LONG_PRESS_DETECTED) {
151
+
Serial.println(F("Long press of 1000 ms just detected"));
152
+
sLongPressMessageSent = true; // Print message only once per long press
119
153
}
154
+
120
155
```
121
156
157
+
158
+
if (sLCDDisplayPage == POWER_METER_PAGE_INFO && PageButtonAtPin3.checkForLongPress(1000) == EASY_BUTTON_LONG_PRESS_DETECTED) {
159
+
160
+
122
161
## Double press detection
123
-
Call checkForDoublePress() only from button press callback function. It will not work as expected called outside this callback function.
124
-
Be aware, that the first press after booting may be detected as double press!
125
-
This is because the "last time of press" `ButtonReleaseMillis` is initialized with 0 milliseconds, which is interpreted as the first press happened at the beginning of boot.
162
+
**Call checkForDoublePress() only from button press callback function**. It will not work as expected, if called outside this callback function.
126
163
127
164
```c++
128
165
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
@@ -144,10 +181,13 @@ void setup() {}
144
181
void loop() {}
145
182
```
146
183
147
-
## Handling the `multiple definition` error
184
+
<br/>
185
+
186
+
# Handling the `multiple definition` error
148
187
If you get the error `multiple definition of __vector_1` (or `__vector_2`) because another library uses the attachInterrupt() function,
149
-
then activate the line `#define USE_ATTACH_INTERRUPT` in *EasyButtonAtInt01.h* or
150
-
define global symbol with `-DUSE_ATTACH_INTERRUPT` which is not yet possible in Arduino IDE :disappointed:.<br/>
188
+
then insert the line `#define USE_ATTACH_INTERRUPT` in your program **before** the line `#include "EasyButtonAtInt01.hpp"`.
189
+
190
+
<br/>
151
191
152
192
153
193
# Compile options / macros for this library
@@ -156,7 +196,7 @@ These macros must be defined in your program **before** the line `#include "Easy
156
196
Modify them by enabling / disabling them, or change the values if applicable.
157
197
158
198
| Name | Default value | Description |
159
-
|-|-|-|
199
+
|-|-:|-|
160
200
|`USE_BUTTON_0`| disabled | Enables code for button at INT0 (pin2 on 328P, PB6 on ATtiny167, PB2 on ATtinyX5). The macro INT0_PIN is set after the include. |
161
201
|`USE_BUTTON_1`| disabled | Enables code for button at INT1 (pin3 on 328P, PA3 on ATtiny167, PCINT0 / PCx for ATtinyX5). The macro INT1_PIN is set after the include. |
162
202
|`INT1_PIN`| % | It overrides the usage of pin at the processors INT1 pin. Thus, it is the pin number of the pin for button 1 to use with Pin Change Interrupts. |
@@ -172,20 +212,6 @@ Modify them by enabling / disabling them, or change the values if applicable.
172
212
173
213
The exact pin numbers of the buttons used internally are available by the macros INT0_PIN and INT1_PIN, which are set after the include.
174
214
175
-
### Changing include (*.h) files with Arduino IDE
176
-
First, use *Sketch > Show Sketch Folder (Ctrl+K)*.<br/>
177
-
If you have not yet saved the example as your own sketch, then you are instantly in the right library folder.<br/>
178
-
Otherwise you have to navigate to the parallel `libraries` folder and select the library you want to access.<br/>
179
-
In both cases the library source and include files are located in the libraries `src` directory.<br/>
180
-
The modification must be renewed for each new library version!
181
-
182
-
### Modifying compile options / macros with PlatformIO
183
-
If you are using PlatformIO, you can define the macros in the *[platformio.ini](https://docs.platformio.org/en/latest/projectconf/section_env_build.html)* file with `build_flags = -D MACRO_NAME` or `build_flags = -D MACRO_NAME=macroValue`.
184
-
185
-
### Modifying compile options / macros with Sloeber IDE
186
-
If you are using [Sloeber](https://eclipse.baeyens.it) as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
sentence=Small and easy to use Arduino library for using push buttons at INT0/pin2 and / or any PinChangeInterrupt pin.<br/>Functions for long and double press detection are included.<br/><br/>Just connect buttons between ground and any pin of your Arduino - that's it<br/><br/><b>No call</b> of begin() or polling function like update() required. No blocking debouncing delay.<br/>
6
-
paragraph=<br/>Define an EasyButtonIn in you main program and use <i>ButtonStateIsActive</i> or <i>ButtonToggleState</i> to determine your action.<br/>Or use a <b>callback function</b> which will be called once on every button press or release.<br/><br/>Usage:<pre>#define USE_BUTTON_0<br/>#include "EasyButtonAtInt01.hpp"<br/>EasyButton Button0AtPin2;<br/><br/>void setup() {}<br/>void loop() {<br/>...<br/> digitalWrite(LED_BUILTIN, Button0AtPin2.ButtonToggleState);<br/>...<br/>}</pre><br/><br/><b>New: </b>Avoid mistakenly double press detection after boot.</b><br/>
5
+
sentence=Small and easy to use Arduino library for using push buttons at any PinChangeInterrupt pin. Automatic debouncing, no delay required. Functions for long and double press detection are included.
6
+
paragraph=Define an EasyButton in you main program and use a callback function which will be called once on every button press or release.
boolgetButtonStateIsActive(); // get private member
294
295
boolreadDebouncedButtonState();
295
296
boolupdateButtonState();
296
297
uint16_tupdateButtonPressDuration(); // Updates the ButtonPressDurationMillis by polling, since this cannot be done by interrupt.
@@ -304,7 +305,6 @@ class EasyButton {
304
305
voidhandleINT01Interrupts(); // internal use only
305
306
306
307
bool LastBounceWasChangeToInactive; // Internal state, reflects actual reading with spikes and bouncing. Negative logic: true / active means button pin is LOW
307
-
volatilebool ButtonStateIsActive; // State at last change. Negative logic: true / active means button pin is LOW. If last press duration < BUTTON_DEBOUNCING_MILLIS it holds wrong value (true instead of false) :-(
308
308
volatilebool ButtonToggleState; // Toggle is on press, not on release - initial value is false
309
309
310
310
/*
@@ -351,6 +351,13 @@ class EasyButton {
351
351
#if defined(USE_BUTTON_1)
352
352
static EasyButton *sPointerToButton1ForISR;
353
353
#endif
354
+
355
+
private:
356
+
/*
357
+
* If last press duration < BUTTON_DEBOUNCING_MILLIS it holds wrong value (true instead of false), therefore it is private.
358
+
* To get current state, use readButtonState().
359
+
*/
360
+
volatilebool ButtonStateIsActive; // State at last change. Negative logic: true / active means button pin is LOW.
0 commit comments