I have made a code for a foot controlled midi pedal. At first i tried to debounce the buttons with delay, but as you might expect that doesnt work very well. So i tried the change the code with millis() and debouncedelay. But im not sure if i doing it the right way. Below is a piece of the code that i have changed. Is this the way to go?
shiftOn = digitalRead(notes[8]);
if ( (millis() - lastDebounceTime) > debounceDelay) {
if (shiftOn == HIGH) && (shiftOn != shiftOnLast){
if (mode == 0) {
mode = 1;
digitalWrite(39, HIGH);
lastDebounceTime = millis();
}
else if (mode == 1) {
mode = 0;
digitalWrite(39, LOW);
lastDebounceTime = millis();
}
shiftOnLast = shiftOn;
}
if ((shiftOn == LOW) && (shiftOn != shiftOnLast)) {
shiftOnLast = shiftOn;
lastDebounceTime = millis();
}
}