You've all set a clock before, you put it into set time mode and the number you're trying to set blinks. If you click the button, it increments by one. This is what I'm trying to do on an arduino, but I'm trying to implement it all with one button. Ideally you hold it down for a couple seconds to enter time set mode, that I have figured out. However I am completely lost as to go from there and after playing around for a few hours I'm no closer. I would like clicking the button once to increment the hour by one, and if you hold it down for 2-3 seconds it switches to setting the minute. Holding it down for another 2-3 seconds will set it as the correct time in the clock and exit the function. I'm not sure how difficult this is to do with one button, but I'm finding it a huge struggle.
This is the code I have so far after the device enters "time set mode"
void setTime() {
rtc.update();
int oldHour = rtc.hour();
int oldMinute = rtc.minute();
display.clearDisplay();
display.display();
int duration = 0;
while (true) {
if (digitalRead(8) == LOW) {
printClock(oldHour, oldMinute);
delay(900);
printClock(0, oldMinute);
delay(900);
} else if (digitalRead(8) == HIGH) {
duration++;
Serial.println(duration);
delay(50);
if ((duration > 1) && (duration < 2)) {
Serial.println("it works");
duration = 0;
oldHour++;
}
}
}
}
It doesn't do much because I couldn't even get passed the first part of increasing the hour by one each button press. The code doesn't work at all, but I did make an attempt :I. Any help would be appreciated. Thank you!