Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4760e5e

Browse files
committedJun 13, 2022
Update
Update readme, library.properties and library.json
1 parent 86af999 commit 4760e5e

File tree

4 files changed

+15
-81
lines changed

4 files changed

+15
-81
lines changed
 

‎README.md

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,20 @@
11
# Toggle [![arduino-library-badge](https://www.ardu-badge.com/badge/Toggle.svg?)](https://www.ardu-badge.com/Toggle) [![PlatformIO Registry](https://badges.registry.platformio.org/packages/dlloydev/library/Toggle.svg)](https://registry.platformio.org/libraries/dlloydev/Toggle)
22

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.
3+
Arduino button debounce library for various switch types, port expanders and other 8-bit data sources. Fast and robust debounce algorithm.
44

55
## Features
66

7-
### Flexible Inputs
7+
- Fast, robust and symetrical [debouncing](https://github.com/Dlloydev/Toggle/wiki/Debounce-Algorithm) of both press and release button transitions
8+
- Works with various [switch types](https://github.com/Dlloydev/Toggle/wiki/Switch-Connections)
9+
- Identifies 7 unique transitions for 3-position switches
10+
- Use momentary button as toggle switch (configurable)
11+
- Return up to 225 codes from one button
812

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).
13+
## Examples
1014

11-
### Debounce Algorithm
15+
- Lets give some examples a [trial run](https://github.com/Dlloydev/Toggle/wiki/Wokwi-Examples).
1216

13-
The debounce 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.![image](https://user-images.githubusercontent.com/63488701/171260623-befe88a4-66c4-44a2-a38b-6c14c715a92d.png)
14-
15-
| ppDat | pDat | dat | **R** | **S** | **Q** | **State** |
16-
| ----- | ---- | ---- | ----- | ----- | ---------- | --------- |
17-
| 0 | 0 | 0 | 1 | 0 | 0 | Reset |
18-
| 0 | 0 | 1 | 0 | 0 | Last State | No Change |
19-
| 0 | 1 | 0 | 0 | 0 | Last State | No Change |
20-
| 0 | 1 | 1 | 0 | 0 | Last State | No Change |
21-
| 1 | 0 | 0 | 0 | 0 | Last State | No Change |
22-
| 1 | 0 | 1 | 0 | 0 | Last State | No Change |
23-
| 1 | 1 | 0 | 0 | 0 | Last State | No Change |
24-
| 1 | 1 | 1 | 0 | 1 | 1 | Set |
25-
26-
### Sampling
27-
28-
The sample period defaults to 5000 μs. With this setting, only 15ms is required for detecting a button switch being pressed or released. This may seem low when thinking of regular debouncig, but in order for this method to falsely detect a transition, it would require that there be a gap of greater than 15ms between bounces. From *[A Guide to Debouncing](http://www.ganssle.com/item/debouncing-switches-contacts-code.htm)*, (Anatomy of a Bounce):
29-
30-
> *Consider switch E again, that one with the pretty face that hides a vicious 157 msec bouncing heart. One test showed the switch going to a solid one for 81 msec, after which it dropped to a perfect zero for 42 msec before finally assuming its correct high state. Think what that would do to pretty much any debounce code!*
31-
32-
Using the Toggle library, this switch could be debounced with a 15ms sample period and ignoring dropouts of up to 45ms.
33-
34-
## Switch Connections
35-
36-
Switching between GND and digital pin is the default solution used by this library. External pull-up resistors can be added if desired, but the internal pullups should be sufficient for most applications. What might be of consideration is providing sufficient wetting current to overcome switch contact oxidation.
37-
38-
A set of connections are shown where 0.1μF capacitors are optionally added. This adds contact wetting current and hardware signal filtering (beneficial for interrupt applications) .
39-
40-
41-
42-
#### Connections shown below are for 2-position switches (SPST, SPDT, DPDT) using 1 input:
43-
44-
![image](https://user-images.githubusercontent.com/63488701/166920176-7bd21bb6-10f9-4cd1-9467-0c2289e698c5.png)
45-
46-
![image](https://user-images.githubusercontent.com/63488701/166920355-3edac199-4aae-4615-a790-152c2f3acec5.png)
47-
48-
49-
50-
#### Connections shown below are for 3-position switches (SP3T, DP3T) using 2 inputs:
51-
52-
53-
54-
#### Toggle Switch (SP3T, On-Off-On):
55-
56-
![image](https://user-images.githubusercontent.com/63488701/166512833-eda91d35-60bd-4846-95cb-326a442edfac.png)
57-
58-
59-
60-
#### Slide Switch (Single Pole, 3-position):
61-
62-
![image](https://user-images.githubusercontent.com/63488701/166516607-82f0c9c1-e627-4769-bb15-5df6c0bd8784.png)
63-
64-
65-
66-
#### Rotary Switch (Double Pole, 3-position):
67-
68-
![image](https://user-images.githubusercontent.com/63488701/166517355-0869726d-dca0-4125-bb3e-2bebe63f6afb.png)
69-
70-
#### The switch functions when using 2 input pins:
71-
72-
```
73-
isUP();
74-
isMID();
75-
isDN();
76-
UPtoMID();
77-
MIDtoDN();
78-
DNtoMID();
79-
MIDtoUP();
80-
```
81-
82-
The switch has 3 positions referred to as UP, MID (center) and DN (down). The first 3 functions will continuously return true if the switch is at that position. The last 4 functions return true (once only) if the switch has just transitioned to that position.
17+
- See sketch [examples](https://github.com/Dlloydev/Toggle/tree/main/examples).
8318

8419

8520

@@ -401,9 +336,9 @@ if (retrigger(500)) {
401336
byte pCode = sw1.pressCode(1); // (1) serial print results
402337
```
403338

404-
##### Example Sketch
339+
##### Example Sketch [Press_Code.ino](https://github.com/Dlloydev/Toggle/blob/main/examples/Press_Code/Press_Code.ino)
405340

406-
[Press_Code.ino](https://github.com/Dlloydev/Toggle/blob/main/examples/Press_Code/Press_Code.ino)
341+
[Trial run on *WOKWi*](https://wokwi.com/projects/334284248581145170)
407342

408343

409344

‎examples/Press_Code/Press_Code.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ void setup() {
2121

2222
void loop() {
2323
sw1.poll();
24-
sw1.pressCode(1); // open serial monitor to view results
25-
//code = sw1.pressCode(); // no debug
24+
sw1.pressCode(1); // print: (1) on () off
2625
}

‎library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Toggle",
33
"version": "3.1.6",
4-
"description": "Arduino bounce library for debouncing hardware, signals and data. Works with all switch types, port expander and other 8-bit data sources. Robust debounce algorithm.",
4+
"description": "Arduino button debounce library for various switch types, port expanders and other 8-bit data sources. Fast and robust debounce algorithm.",
55
"keywords": "debounce, toggle, button, switch, data, deglitch",
66
"repository":
77
{

‎library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name=Toggle
22
version=3.1.6
33
author=David Lloyd
44
maintainer=David Lloyd <dlloydev@testcor.ca>
5-
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.
6-
paragraph=Robust debounce algorithm.
5+
sentence=AArduino button debounce library for various switch types, port expanders and other 8-bit data sources.
6+
paragraph= Fast and robust debounce algorithm.
77
category=Signal Input/Output
88
url=https://github.com/Dlloydev/Toggle
99
architectures=*

0 commit comments

Comments
 (0)
Please sign in to comment.