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
#defineBUTTON_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
+
172
172
voidsetup() {
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.
176
176
}
177
-
177
+
178
178
voidloop() {
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.
181
181
}
182
182
```
183
183
@@ -188,23 +188,23 @@ Click [ here](examples/Toggle/Toggle.ino) the Toggle sketch.
188
188
```c
189
189
#include"ADebouncer.h"
190
190
191
-
#definebuttonPin 12 // Define the button input pin.
192
-
#define debouncePeroid 10 // Define the debounce period in milliseconds
191
+
#defineBUTTON_INPUT_PIN 12 // Define the button input pin.
192
+
#define DEBOUNCE_PERIOD_MS 10 // Define the debounce period in milliseconds
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.
202
202
}
203
203
204
204
voidloop() {
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.
208
208
}
209
209
```
210
210
@@ -223,27 +223,32 @@ Click [ here](examples/ResetSet/ResetSet.ino) the ResetSet sketch.
223
223
```c
224
224
#include"ADebouncer.h"
225
225
226
-
#definesetPin 12 // Define the set input pin.
227
-
#defineresetPin 11 // Define the reset input pin.
228
-
#definedebouncePeroid 1000 // Define the debounce period in milliseconds
226
+
#defineSET_PIN 12 // Define the set input pin.
227
+
#defineRESET_PIN 11 // Define the reset input pin.
228
+
#defineDEBOUNCE_PERIOD_MS 1000 // Define the debounce period in milliseconds
229
229
230
230
ADebouncer setButton; // Declare set debouncer variable.
bool state; // Declare state variable for ResetSet.
233
233
234
234
voidsetup() {
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.
241
241
}
242
242
243
243
voidloop() {
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();
0 commit comments