I have an issue with this countdown timer of mine. It seems that the countdown portion is not in sync with the seconds as it supposed to be. can somebody tell me 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);
}