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
Added new functions to set and get the timer mode. Now the timer can start onPress, onRelease or onChange events.
New retrigger on press example added.
setAlgorithm(0); // Quick Mode, responds to spurious transitions
39
39
```
40
40
41
41
In Robust Mode, the algorithm adds only 2 sample periods of time lag to the output signal. A 3-sample stable period is required for an output bit to change. Therefore, to set an output bit, 3 consecutive 1's are required. When 3 consecutive 0's are detected, that bit value is cleared.
@@ -113,7 +113,7 @@ To use this library
113
113
## Constructors
114
114
115
115
```c++
116
-
Toggle();// default constructor
116
+
Toggle();
117
117
Toggle(inA);
118
118
Toggle(inA, inB);
119
119
Toggle(*in);
@@ -123,18 +123,14 @@ Toggle(*in);
123
123
124
124
The constructor defines a button object. If the default constructor is used when declaring an array of pointers to button objects, then it must be followed by a call to begin in setup.
**inA:** Arduino pin number that the button or switch is connected to *(byte)* , <u>or</u>
133
-
***in:** Arduino variable representing the input signal *(byte)*
128
+
**inA:** Arduino pin number that the button or switch is connected to *(byte)* , <u>or</u>
129
+
***in:** Arduino variable representing the input signal *(byte)*
134
130
135
-
##### Optional parameters
131
+
##### Optional parameter
136
132
137
-
**inB:** Second Arduino pin number *(byte)*. Use 2 inputs when connecting to 3 position switches.
133
+
**inB:** Second Arduino pin number *(byte)*. Use 2 inputs when connecting to 3 position switches.
138
134
139
135
##### Returns
140
136
@@ -143,11 +139,11 @@ None.
143
139
##### Example
144
140
145
141
```c++
146
-
// a button or switch is connected from pin 2 to ground
147
-
// 5ms sample interval (default)
148
-
// pullup enabled (default)
149
-
// inverted = false (default)
150
-
// algorithm = 2 glitches "Robust Mode" (default)
142
+
/* a button or switch is connected from pin 2 to ground
143
+
5000 μs sample interval (default)
144
+
pullup enabled (default)
145
+
inverted = false (default)
146
+
algorithm = 2 glitches "Robust Mode" (default) */
151
147
Toggle myInput(2);
152
148
153
149
// same as above, but a 3 position switch is connected to pins 2 and 3
@@ -169,9 +165,9 @@ This function is placed at the top of the loop. Initializes the Button object an
169
165
170
166
`myInput.poll();`
171
167
172
-
##### Parameters
168
+
##### Optional parameter
173
169
174
-
None.
170
+
**bit:** selects the bit number from an input data *(byte)*
175
171
176
172
##### Returns
177
173
@@ -246,7 +242,7 @@ None.
246
242
```c++
247
243
if (myInput.onPress())
248
244
{
249
-
//do something (true only once per press)
245
+
//do something (true only once per press)
250
246
}
251
247
```
252
248
@@ -277,13 +273,11 @@ These functions checks the curent debounced output and its history to see if the
277
273
##### Example
278
274
279
275
```c++
280
-
if (myButton.isPressed())
281
-
{
282
-
//do something
276
+
if (myButton.isPressed()) {
277
+
// do something
283
278
}
284
-
else
285
-
{
286
-
//do something else
279
+
else {
280
+
// do something else
287
281
}
288
282
```
289
283
@@ -319,7 +313,7 @@ There are 4 timer functions to make timing operations simple to use in your code
319
313
320
314
##### Description
321
315
322
-
This function sets the duration in milliseconds that the returned value is true after each state change. Useful to blink an LED to indicate every state change.
316
+
This function sets the duration in milliseconds that the returned value is true after the set timer mode - onPress( 0), onRelease (1), onChange (2). Useful to blink an LED.
323
317
324
318
##### Syntax
325
319
@@ -347,7 +341,7 @@ digitalWrite(ledPin, blink(100)); // blink an LED for 100ms just after each stat
347
341
348
342
##### Description
349
343
350
-
These functions check the the status register to see if the button or switch has set the pressedFor or releasedFor flag. These functions will return the flag status and clear the respective flag.
344
+
These functions return true if the button or switch has been in the pressedFor or releasedFor state for at least the given number of milliseconds.
351
345
352
346
##### Syntax
353
347
@@ -365,9 +359,8 @@ These functions check the the status register to see if the button or switch has
365
359
##### Example
366
360
367
361
```c++
368
-
if (myInput.pressedFor(500))
369
-
{
370
-
// true (once only) if button has been pressed for 500ms
362
+
if (myInput.pressedFor(500)) {
363
+
// true (once only) if button has been pressed for 500ms
371
364
}
372
365
```
373
366
@@ -377,7 +370,7 @@ if (myInput.pressedFor(500))
377
370
378
371
##### Description
379
372
380
-
This function checks the duration in milliseconds that the button or switch is pressed and returns true (once only) each time the given millisecond duration has expired.
373
+
This function checks the duration in milliseconds that the button or switch is is in the state as selected by timer mode and returns true (once only) each time the given millisecond duration has expired.
381
374
382
375
##### Syntax
383
376
@@ -389,20 +382,19 @@ This function checks the duration in milliseconds that the button or switch is
389
382
390
383
##### Returns
391
384
392
-
*true* or *false*, returns true (once only) each time the given ms duration has expired while the button is pressed. *(bool)*
385
+
*true* or *false*, returns true (once only) each time the given ms duration has expired while the button is in the state as selected by timer mode. *(bool)*
393
386
394
387
##### Example
395
388
396
389
```c++
397
-
if (retrigger(500))
398
-
{
390
+
if (retrigger(500)) {
399
391
// count every 500ms interval while the button is being pressed
400
392
}
401
393
```
402
394
403
395
404
396
405
-
## Set Functions
397
+
## Set and Get Functions
406
398
407
399
408
400
@@ -452,7 +444,7 @@ None.
452
444
453
445
##### Description
454
446
455
-
Sets the sample period in microseconds. Default is 5000μs.
447
+
Sets the sample period in microseconds. Default is 5000 μs.
456
448
457
449
##### Syntax
458
450
@@ -464,6 +456,54 @@ None.
464
456
465
457
466
458
459
+
## setTimerMode()
460
+
461
+
##### Description
462
+
463
+
Sets the timer mode to start onPress (0), onRelease (1) or onChange (2).
464
+
465
+
##### Syntax
466
+
467
+
`myInput.setTimerMode(0);`
468
+
469
+
##### Returns
470
+
471
+
None.
472
+
473
+
474
+
475
+
## getTimerMode()
476
+
477
+
##### Description
478
+
479
+
Gets the timer mode to start onPress (0), onRelease (1) or onChange (2).
480
+
481
+
##### Syntax
482
+
483
+
`myInput.getTimerMode();`
484
+
485
+
##### Returns
486
+
487
+
Timer Mode *(byte)*.
488
+
489
+
490
+
491
+
## getElapsedMs(()
492
+
493
+
##### Description
494
+
495
+
Gets the elapsed ms since the last state change selected by timer mode.
Copy file name to clipboardExpand all lines: library.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "Toggle",
3
-
"version": "3.0.1",
3
+
"version": "3.0.2",
4
4
"description": "Arduino bounce library for deglitching and debouncing hardware, signals and data. Works with all switch types, port expander and other 8-bit data sources. Flexible algorithm with Robust, Normal and Quick response modes.",
sentence=Arduino bounce library for deglitching and debouncing hardware, signals and data. Works with all switch types, port expander and other 8-bit data sources.
0 commit comments