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
pinMode(buttonPin, INPUT_PULLUP); // Set the button mode as input pullup.
173
+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
174
+
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.
175
+
}
176
+
177
+
voidloop() {
178
+
bool buttonState = debouncer.debounce(digitalRead(buttonPin)); // Save the debounced of the button state.
179
+
digitalWrite(LED_BUILTIN, buttonState); // Update LED_BUILTIN with the button state.
180
+
}
181
+
```
159
182
160
183
## Toggle
161
184
Declare debounce mode as delayed mode. Debounce the input signal from the button. Toggle the state when pressing the button and update LED_BUILTIN with the toggle state.
162
185
163
186
Click [ here](examples/Toggle/Toggle.ino) the Toggle sketch.
187
+
```c
188
+
#include"ADebouncer.h"
189
+
190
+
#definebuttonPin 12 // Define the button input pin.
191
+
#define debouncePeroid 10 // Define the debounce period in milliseconds
bool state; // Declare state variable for ResetSet.
232
+
233
+
voidsetup() {
234
+
pinMode(setPin, INPUT_PULLUP); // Set the button mode as input pullup.
235
+
pinMode(resetPin, INPUT_PULLUP); // Set the button mode as input pullup.
236
+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
237
+
setButton.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
238
+
resetButton.mode(INSTANT, debouncePeroid, HIGH); // Set the debounce mode as instant mode and debounce period, with the initial output in a HIGH state.
239
+
state = LOW; // Initial state in a LOW state.
240
+
}
241
+
242
+
voidloop() {
243
+
setButton.debounce(digitalRead(setPin)); // Debounce input of the set button state.
244
+
resetButton.debounce(digitalRead(resetPin)); // Debounce input of the reset button state.
245
+
state = (state | !setButton.debounced()) & resetButton.debounced(); // Reset and Set the state
246
+
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
0 commit comments