I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.
void inizio(){
Serial.println("INIZIO");
currentMillis1_general = millis();
total_1 = currentMillis1_general - currentMillis_general;
Serial.println(total_1);
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
step_funzione = 1;
delay(200);
}
}
void countdown(){
Serial.println("COUNTDOWN");
display.setBrightness(7);
currentMillis_general = millis();
total_general = currentMillis_general - total_1;
if(total_general - previousMillis_general >= interval_general){
previousMillis_general += interval_general;
//previousMillis_general = currentMillis_general;
m = new_tempo/60;
s = new_tempo%60;
new_tempo--;
}
display.showNumberDec(m, true,2,0);
display.showNumberDec(s, true,2,2);
Serial.println(total_general);
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
step_funzione = 0;
delay(200);
}
}
-
3think about this ....How do you know when it is time to replace the oil in your car's engine? .... you cannot reset the odometer to zerojsotola– jsotola2018年06月24日 19:10:23 +00:00Commented Jun 24, 2018 at 19:10
1 Answer 1
A way to accomplish "Reset" is to set your starting value equal to millis() again. To do the equivalent of "Pause", you need a pause counter. When you begin a pause, save millis() to pauseTime
. When you resume running again, add millis() - pauseTime
to your pauseCounter. Then your interval should not expire until millis() - pauseCounter > Interval)
.