Folks
I'm truing to get a debounce timer to work correctly.
There are 2 buttons that need the debounce , gear_R++ and gear_R-
With out the debnounce the code works fine. With not so much. Can any provide some guidance?
The code is as follows
(defined at the beginning)
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void loop() {
if(digitalRead(B_R)==HIGH)
{
// read the state of the switch into a local variable:
int reading = digitalRead(B_G_F);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
#include <DebouncedSwitch.h>
DebouncedSwitch sw4(4); // monitor a switch on input D4
DebouncedSwitch sw5(5); // monitor a switch on input D5
void loop() {
sw4.update(); // call this every loop to update switch state
sw5.update(); // call this every loop to update switch state
// etc
if (sw4.isDown()) {
// do something
}
if (sw5.isChanged()) { // debounced switch changed state Up or Down
// isChanged() is only true for one loop(), cleared when update() called again
if (!sw5.isDown()) { // switch was just released
// do something first time switch becomes down
}
}