Hello!
I'm trying to build a program for two TM1637 displays and an RTC; I have time / date setting functions, but the buttons work a bit hard, and I should fix this. For example:
void DisplaySetMinute();
{
Display1.clear();
if (digitalRead(P2) == LOW) {
if (myMinute == 59) {
myMinute = 0;
} else {
myMinute = myMinute + 1;
}
}
if (digitalRead(P3) == LOW) {
if (myMinute == 0) {
myMinute = 59;
} else {
myMinute = myMinute - 1;
}
}
Display1.showNumberDec((myMinute / 10) % 10, false, 1, 2);
Display1.showNumberDec(myMinute % 10, false, 1, 3);
delay(200);
}
void DisplaySetMinute();
{
Display1.clear();
if (millis() - lastDebounceTime > debounceDelay) { // 50 ms
if (readingP2 != buttonState) {
buttonState = readingP2;
if (digitalRead(P2) == HIGH) {
if (myMinute == 59) {
myMinute = 0;
} else {
myMinute = myMinute + 1;
}
}
}
}
lastButtonState = readingP2;
if (millis() - lastDebounceTime > debounceDelay) {
if (readingP3 != buttonState) {
buttonState = readingP3;
if (digitalRead(P3) == HIGH) {
if (myMinute == 0) {
myMinute = 59;
} else {
myMinute = myMinute - 1;
}
}
}
}
lastButtonState = readingP3;
Display1.showNumberDec((myMinute / 10) % 10, false, 1, 2);
Display1.showNumberDec(myMinute % 10, false, 1, 3);
//delay(200);
}
In my mind, I said that I have to do debouncing in each function, but with the same buttons I think that the states are interspersed, because I can't set anything on the display anymore.
How do you suggest to accomplish debouncing in this case?
sketch_oct10a.ino (5.4 KB)