|
1 | 1 | # Toggle [](https://www.ardu-badge.com/Toggle) [](https://registry.platformio.org/libraries/dlloydev/Toggle) |
2 | 2 |
|
3 | | - Arduino button library for debouncing switch contacts and logic data. New pressCode() function detects fast, short and long button presses for 225 combinations. Works with all switch types, port expanders and other 8-bit data sources. Debounce algorithm ignores several consecutive spurious transitions. |
| 3 | +Arduino button library for debouncing switch contacts and input data. New pressCode() function detects fast, short and long button presses for 225 combinations. Works with all switch types, port expanders and other 8-bit data sources. Debounce algorithm ignores several consecutive spurious transitions. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | 7 | ### Flexible Inputs |
8 | 8 |
|
9 | | -The inputs can be from a single pin or several pins allowing the use of 2 or 3-position switches and up to seven debounced states. When linking to a data (byte) input, the debouncer can work with any selected bit or it can debounce all 8-bits in one Toggle instance. Examples: [`Input_Bit_Test.ino`](https://github.com/Dlloydev/Toggle/blob/main/examples/Input_Bit_Test/Input_Bit_Test.ino) , [`Input_Bit.ino`](https://github.com/Dlloydev/Toggle/blob/main/examples/Input_Bit/Input_Bit.ino), [`Input_Port_Test.ino`](https://github.com/Dlloydev/Toggle/blob/main/examples/Input_Port_Test/Input_Port_Test.ino) and [`Input_Port.ino`](https://github.com/Dlloydev/Toggle/blob/main/examples/Input_Port/Input_Port.ino). |
| 9 | +The inputs can be from a single pin or several pins allowing the use of 2 or 3-position switches and up to seven debounced states. When linking to a data (byte) input, the debouncer can work with any selected bit or it can debounce all 8-bits in one Toggle instance. See [examples](https://github.com/Dlloydev/Toggle/tree/main/examples). |
10 | 10 |
|
11 | 11 | ### Debounce Algorithm |
12 | 12 |
|
@@ -122,15 +122,9 @@ None. |
122 | 122 | ##### Example |
123 | 123 |
|
124 | 124 | ```c++ |
125 | | -// a button or switch is connected from pin 2 to ground, 5000 μs sample interval (default), |
126 | | -// pullup enabled (default), inverted = false (default) |
127 | | -Toggle myInput(2); |
128 | | -
|
129 | | -// same as above, but a 3 position switch is connected to pins 2 and 3 |
130 | | -Toggle myInput(2, 3); |
131 | | -
|
132 | | -// a byte variable is linked to the Toggle object, defaults are same as above |
133 | | -Toggle myInput(*Input); |
| 125 | +Toggle myInput(2); // Button connected pin 2 to GND, INPUT_PULLUP, debounced |
| 126 | +Toggle myInput(2, 3); // SPDT switch connected pins 2 and 3 to GND, INPUT_PULLUP, debounced |
| 127 | +Toggle myInput(*Input); // Byte variable as input, debounced |
134 | 128 | ``` |
135 | 129 |
|
136 | 130 |
|
@@ -267,19 +261,18 @@ else { |
267 | 261 |
|
268 | 262 | ##### Description |
269 | 263 |
|
270 | | -This function will toggle the return value after each `onPress` state change. Useful to easily toggle an LED. |
| 264 | +This function can be used to convert a momentary push button to a toggle switch. By default, the retuen value will toggle `true-false` then `false-true` for each `onPress` action of the button. |
271 | 265 |
|
272 | | -##### Syntax |
273 | | - |
274 | | -`myInput.toggle(invert);` |
| 266 | +- The `setToggleState()` function sets the initial state (*true* or *false*) |
| 267 | +- The `setToggleTrigger()` function sets the trigger mode: *false*: `onPress`, *true*: `onRelease` |
275 | 268 |
|
276 | 269 | ##### Parameters |
277 | 270 |
|
278 | | -**invert:** can be used to invert the initial toggle state *(bool)* |
| 271 | +None. |
279 | 272 |
|
280 | 273 | ##### Returns |
281 | 274 |
|
282 | | -*true* or *false*, toggles after each `onPress` state change. *(bool) |
| 275 | +*true* or *false*, (*bool*). Toggles as configured by `setToggleTrigger()`. Default is trigger `onPress` |
283 | 276 |
|
284 | 277 |
|
285 | 278 |
|
@@ -420,21 +413,20 @@ None. |
420 | 413 | myInput.setInputMode(sw1.inMode::input_input); // high impedance input |
421 | 414 | myInput.setInputMode(sw1.inMode::input_pullup); // pullup resistor enabled (default) |
422 | 415 | myInput.setInputMode(sw1.inMode::input_pulldown); // pulldown resistor enabled (ESP32) |
423 | | -myInput.setInputMode(sw1.inMode::input_bit); // input byte (bit0) |
424 | | -myInput.setInputMode(sw1.inMode::input_port); // input byte (8-bit) |
| 416 | +myInput.setInputMode(sw1.inMode::input_byte); // input byte (8-bit) |
425 | 417 | ``` |
426 | 418 |
|
427 | 419 |
|
428 | 420 |
|
429 | | -## setInvertMode() |
| 421 | +## setInputInvert() |
430 | 422 |
|
431 | 423 | ##### Description |
432 | 424 |
|
433 | 425 | Set true if the button or switch pulls the signal high when pressed. Default is false (button or switch pulls the signal low when pressed). |
434 | 426 |
|
435 | 427 | ##### Syntax |
436 | 428 |
|
437 | | -`myInput.setInvertMode(true);` |
| 429 | +`myInput.setInputInvert(true);` |
438 | 430 |
|
439 | 431 | ##### Returns |
440 | 432 |
|
|
0 commit comments