Hi Folks -
maybe somebody can help me with my counter. It seems that the counter i have isnt in sync with the seconds. For example if i set my countdown timer to 60seconds and i do start on a phone a countdown timer also to 60seconds when i hit the 00:00 mark on my counter on the phone i still have 7-10seconds left
what am I doing wrong ?
void countdown(){
unsigned const intervalTime = 1000;
unsigned long previousTime;
unsigned long currentTime = millis();
if(currentTime - previousTime >= intervalTime){
if (countdowntime > 0) countdowntime--;
else countdowntime = 0;
displayevent();
previousTime += intervalTime;
}
}
void displayevent(){
//while(countdowntime > 0){
int seconds = numberOfSeconds(countdowntime);
int minutes = numberOfMinutes(countdowntime);
int lminutes = minutes / 10;
int rminutes = minutes % 10;
int lseconds = seconds / 10;
int rseconds = seconds % 10;
if(countdowntime == 0){
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 63); // Display hundreds tens
shiftOut(datapin, clockpin, MSBFIRST, 63); // Display hundreds unit
shiftOut(datapin, clockpin, MSBFIRST, 63); // Display seconds tens
shiftOut(datapin, clockpin, MSBFIRST, 63); // Display seconds unit
digitalWrite(latchpin, HIGH);
blinking();
} else{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, segdisp[lminutes]); // Display hundreds tens
shiftOut(datapin, clockpin, MSBFIRST, segdisp[rminutes]); // Display hundreds unit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[lseconds]); // Display seconds tens
shiftOut(datapin, clockpin, MSBFIRST, segdisp[rseconds]); // Display seconds unit
digitalWrite(latchpin, HIGH);
}