Skip to content

Commit 454fdd4

Browse files
committed
modified: README.md
deleted: examples/ResetSet/temp.ino
1 parent ea58053 commit 454fdd4

File tree

2 files changed

+56
-73
lines changed

2 files changed

+56
-73
lines changed

README.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ADebouncer debouncer;
4242
## Mode
4343
### Syntax:
4444
```c
45-
variableNam.mode(debounce_t debounceMode, unsigned long debouncePeriod, bool initOutput);
45+
variableNam.setMode(debounce_t debounceMode, unsigned long debouncePeriod, bool initOutput);
4646
```
4747

4848
### Parameters
@@ -64,7 +64,7 @@ Initial output state.
6464
Define the debouncer in delayed mode with debounce period of 10 milliseconds and initial output with a HIGH state.
6565

6666
```c
67-
debouncer.mode(DELAYED, 10, HIGH);
67+
debouncer.setMode(DELAYED, 10, HIGH);
6868
```
6969

7070
## Debounce
@@ -90,70 +90,70 @@ bool debounced = debouncer.debounce(digitalRead(buttonPin));
9090

9191
### Debouncing
9292
#### Syntax:
93-
*`bool debouncing = variable.debouncing();`*\
93+
*`bool debouncing = variable.isDebouncing();`*\
9494
Get the debouncing state.
9595

9696
#### Example:
9797
```c
98-
bool debouncing = debouncer.debouncing();
98+
bool debouncing = debouncer.isDebouncing();
9999
digitalWrite(LED_BUILTIN, debouncing);
100100
```
101101
102102
Or,
103103
104104
```c
105-
digitalWrite(LED_BUILTIN, debouncer.debouncing());
105+
digitalWrite(LED_BUILTIN, debouncer.isDebouncing());
106106
```
107107

108-
### Debounced
108+
### getDebouncedOutput
109109
#### Syntax:
110-
*`bool debounced = variable.debounced();`*\
110+
*`bool debounced = variable.getDebouncedOutput();`*\
111111
Get the debounced state.
112112

113113
#### Example:
114114
```c
115-
bool debounced = debouncer.debounced();
115+
bool debounced = debouncer.getDebouncedOutput();
116116
digitalWrite(LED_BUILTIN, debounced);
117117
```
118118
119119
Or,
120120
121121
```c
122-
digitalWrite(LED_BUILTIN, debouncer.debounced());
122+
digitalWrite(LED_BUILTIN, debouncer.getDebouncedOutput());
123123
```
124124

125125
### Rising Edge of the output
126126
#### Syntax:
127-
*`bool risingEdge = variable.rising();`*\
127+
*`bool risingEdge = variable.isRisingEdge();`*\
128128
Get the rising edge of the output.
129129

130130
#### Example:
131131
```c
132-
bool risingEdge = debouncer.rising();
132+
bool risingEdge = debouncer.isRisingEdge();
133133
if (risingEdge) toggle = !toggle;
134134
```
135135

136136
Or,
137137

138138
```c
139-
if (debouncer.rising()) toggle = !toggle;
139+
if (debouncer.isRisingEdge()) toggle = !toggle;
140140
```
141141

142142
### Falling Edge of the output
143143
#### Syntax:
144-
*`bool fallingEdge = variable.falling();`*\
144+
*`bool fallingEdge = variable.isFallingEdge();`*\
145145
Get the falling edge of the output.
146146

147147
#### Example:
148148
```c
149-
bool fallingEdge = debouncer.falling();
149+
bool fallingEdge = debouncer.isFallingEdge();
150150
if (fallingEdge) toggle = !toggle;
151151
```
152152

153153
Or,
154154

155155
```c
156-
if (debouncer.falling()) toggle = !toggle;
156+
if (debouncer.isFallingEdge()) toggle = !toggle;
157157
```
158158

159159
# Example
@@ -163,21 +163,21 @@ Declare debounce mode as delayed mode. Debounce the input signal from the button
163163
Click [ here](examples/Button/Button.ino) the Button sketch.
164164
```c
165165
#include "ADebouncer.h"
166-
167-
#define buttonPin 2 // Define the button input pin.
168-
#define debouncePeroid 10 // Define the debounce period in milliseconds
169-
170-
ADebouncer debouncer; // Declare debouncer variable.
171-
166+
167+
#define BUTTON_INPUT_PIN 2 // Pin for the button input.
168+
#define DEBOUNCE_PERIOD_MS 10 // Debounce period in milliseconds.
169+
170+
ADebouncer buttonDebouncer; // Create a debouncer instance.
171+
172172
void setup() {
173-
pinMode(buttonPin, INPUT_PULLUP); // Set the button mode as input pullup.
174-
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
175-
debouncer.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period as 10 ms, with the initial output in a HIGH state.
173+
pinMode(BUTTON_INPUT_PIN, INPUT_PULLUP); // Set the button input pin as input with pull-up.
174+
pinMode(LED_BUILTIN, OUTPUT); // Set the built-in LED pin as output.
175+
buttonDebouncer.setMode(DELAYED, DEBOUNCE_PERIOD_MS, HIGH); // Set debounce mode to delayed with a 10ms period, starting with a HIGH output.
176176
}
177-
177+
178178
void loop() {
179-
bool buttonState = debouncer.debounce(digitalRead(buttonPin)); // Save the debounced of the button state.
180-
digitalWrite(LED_BUILTIN, buttonState); // Update LED_BUILTIN with the button state.
179+
bool debouncedButtonState = buttonDebouncer.debounce(digitalRead(BUTTON_INPUT_PIN)); // Get the debounced button state.
180+
digitalWrite(LED_BUILTIN, debouncedButtonState); // Update the built-in LED with the debounced button state.
181181
}
182182
```
183183

@@ -188,23 +188,23 @@ Click [ here](examples/Toggle/Toggle.ino) the Toggle sketch.
188188
```c
189189
#include "ADebouncer.h"
190190

191-
#define buttonPin 12 // Define the button input pin.
192-
#define debouncePeroid 10 // Define the debounce period in milliseconds
191+
#define BUTTON_INPUT_PIN 12 // Define the button input pin.
192+
#define DEBOUNCE_PERIOD_MS 10 // Define the debounce period in milliseconds
193193

194-
ADebouncer debouncer; // Declare debouncer variable.
195-
bool state; // Declare state variable.
194+
ADebouncer buttonDebouncer; // Declare debouncer variable.
195+
bool state; // Declare state variable.
196196

197197
void setup() {
198-
pinMode(buttonPin, INPUT_PULLUP); // Set the button mode as input pullup.
199-
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
200-
debouncer.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
201-
state = HIGH; // Initial state in a HIGH state.
198+
pinMode(BUTTON_INPUT_PIN, INPUT_PULLUP); // Set the button mode as input pullup.
199+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
200+
buttonDebouncer.setMode(DELAYED, DEBOUNCE_PERIOD_MS, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
201+
state = HIGH; // Initial state is set to HIGH.
202202
}
203203

204204
void loop() {
205-
debouncer.debounce(digitalRead(buttonPin)); // Debounce input of the button state.
206-
if (debouncer.falling()) state = !state; // Toggle state of the state variable.
207-
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
205+
buttonDebouncer.debounce(digitalRead(BUTTON_INPUT_PIN)); // Debounce input of the button state.
206+
if (buttonDebouncer.isFallingEdge()) state = !state; // Toggle state of the state variable.
207+
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
208208
}
209209
```
210210

@@ -223,27 +223,32 @@ Click [ here](examples/ResetSet/ResetSet.ino) the ResetSet sketch.
223223
```c
224224
#include "ADebouncer.h"
225225

226-
#define setPin 12 // Define the set input pin.
227-
#define resetPin 11 // Define the reset input pin.
228-
#define debouncePeroid 1000 // Define the debounce period in milliseconds
226+
#define SET_PIN 12 // Define the set input pin.
227+
#define RESET_PIN 11 // Define the reset input pin.
228+
#define DEBOUNCE_PERIOD_MS 1000 // Define the debounce period in milliseconds
229229

230230
ADebouncer setButton; // Declare set debouncer variable.
231231
ADebouncer resetButton; // Declare reset debouncer variable.
232232
bool state; // Declare state variable for ResetSet.
233233

234234
void setup() {
235-
pinMode(setPin, INPUT_PULLUP); // Set the button mode as input pullup.
236-
pinMode(resetPin, INPUT_PULLUP); // Set the button mode as input pullup.
237-
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
238-
setButton.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
239-
resetButton.mode(INSTANT, debouncePeroid, HIGH); // Set the debounce mode as instant mode and debounce period, with the initial output in a HIGH state.
240-
state = LOW; // Initial state in a LOW state.
235+
pinMode(SET_PIN, INPUT_PULLUP); // Set the button mode as input pullup.
236+
pinMode(RESET_PIN, INPUT_PULLUP); // Set the button mode as input pullup.
237+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
238+
setButton.setMode(DELAYED, DEBOUNCE_PERIOD_MS, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
239+
resetButton.setMode(INSTANT, DEBOUNCE_PERIOD_MS, HIGH); // Set the debounce mode as instant mode and debounce period, with the initial output in a HIGH state.
240+
state = LOW; // Initial state in a LOW state.
241241
}
242242

243243
void loop() {
244-
setButton.debounce(digitalRead(setPin)); // Debounce input of the set button state.
245-
resetButton.debounce(digitalRead(resetPin)); // Debounce input of the reset button state.
246-
state = (state | !setButton.debounced()) & resetButton.debounced(); // Reset and Set the state
247-
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
244+
// Debounce input of the set button state.
245+
setButton.debounce(digitalRead(SET_PIN));
246+
// Debounce input of the reset button state.
247+
resetButton.debounce(digitalRead(RESET_PIN));
248+
249+
// Update the state based on set and reset button outputs.
250+
state = (state | !setButton.getDebouncedOutput()) & resetButton.getDebouncedOutput();
251+
// Update LED_BUILTIN with the state.
252+
digitalWrite(LED_BUILTIN, state);
248253
}
249254
```

examples/ResetSet/temp.ino

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)