Hi Folks, i need a little guidance on how to create a countup / countdown timer for an arduino uno on a custom 7seg disp.
I have the below code which is not doing what it supposed to do. Any ideas ?
unsigned long timeLimit = 60000; //Count down time in milliseconds 1 minute
#define numberOfSeconds(_time_) ((_time_ / 1000) % 60)
#define numberOfMinutes(_time_) (((_time_ / 1000) / 60) % 60)
void countdown(){
unsigned long timeRemaining = timeLimit - millis();
while(timeRemaining > 0){
int seconds = numberOfSeconds(timeRemaining);
int minutes = numberOfMinutes(timeRemaining);
int lminutes = minutes / 10;
int rminutes = minutes % 10;
int lseconds = seconds / 10;
int rseconds = seconds % 10;
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);
timeRemaining = timeLimit - millis();
}
}