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
if(alleventsButton.switched()) {Serial.println("all_e_B switched."); Serial.print(" all_e_B status to "); Serial.print(alleventsButton.on()); Serial.println(".");}
Copy file name to clipboardExpand all lines: README.md
+67-37Lines changed: 67 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Available at: https://github.com/avandalen/avdweb_Switch
8
8
#### General features of the Switch library
9
9
- Performs not just de-bouncing, but also de-glitching against EMC pulses.
10
10
- External pull-up resistors are not required.
11
-
- Supports also long pressand double click detection.
11
+
- Supports also long press, double click, and single click detection.
12
12
- Callback functions.
13
13
14
14
## Introduction
@@ -52,7 +52,7 @@ It returns "true" if the pin voltage agrees with the one defined by `polarity` (
52
52
53
53
#### pushed()
54
54
55
-
It returns "true" if a button was pushed (switched towards the on position). Use only for push buttons. Note that this is in fact "single-click".
55
+
It returns "true" if a button was pushed (switched towards the on position). Use only for push buttons. Note that this provides instant response and can be used as "single-click" if "double-click" and "long-press" are not watched events. "Pushed" occurs simultaneously with "double-click" and "long-press".
56
56
57
57
#### released()
58
58
@@ -68,6 +68,11 @@ It returns "true" if a push button is double clicked within 250ms (by default).
68
68
69
69
The anteceding pushed() event can't be avoided, because to restrict the pushed() function to single clicks it would have to wait for a possible second click, which would introduce an annoying delay. So, the action on doubleClick() has to undo the previous action on pushed().
70
70
71
+
#### singleClick()
72
+
73
+
It returns "true" if a push button is clicked once and the requirements for doubleClick and longPress are not met. The event thus occur several miliseconds after the actual push, because it depends on the other events not happening after the push. Use this if three different interactions are needed in combination with doubleClick and longPress. Note that a singleClick() always will be preceded by pushed(). Use pushed() instead if immediate response is required and there is no interest in monitoring doubleClick and longPress.
74
+
75
+
71
76
#### Example
72
77
73
78
See the example in the library for a complete working program.
@@ -104,7 +109,7 @@ void setup() {
104
109
}
105
110
```
106
111
107
-
The available callback setting functions are `setPushedCallback()`, `setReleasedCallback()`, `setLongPressCallback()`, and `setDoubleClickCallback()` which allow defining the functions that will be called on such events. If using a toggle switch and not a push button, the "pushed" event will be of interest when the switch is turned on, and "released" when it is turned off.
112
+
The available callback setting functions are `setPushedCallback()`, `setReleasedCallback()`, `setLongPressCallback()`, `setDoubleClickCallback()`, and `setSingleClickCallback()` which allow defining the functions that will be called on such events. If using a toggle switch and not a push button, the "pushed" event will be of interest when the switch is turned on, and "released" when it is turned off.
108
113
109
114
If the conditions for more than one event occur simultaneously and there are callback functions registered for them, they will be executed in the order of the functions above.
110
115
@@ -169,6 +174,10 @@ A long-press generates first a pushed event and after 300ms (by default) the lon
169
174
170
175
The same happens with doubleClick, which also generates two pushed() events. When doubleClick is used, ignore the second pushed() result or don't call pushed(). When doubleClick is not needed, simply don't call doubleClick().
171
176
177
+
#### Combining singleClick, doubleClick, and longPress events
178
+
179
+
If these three events must be used toghether the best strategy is to stick to their get functions and avoid using pushed().
180
+
172
181
## Hardware considerations
173
182
174
183
#### Connecting switches to the microcontroler
@@ -222,68 +231,89 @@ Several discrete signals (updated at poll times) are created. The raw signal is
0 commit comments