hi guys,
i am trying to build a simple countdown with a teensy3.2 with the millis function: but somehow the code is not responding properly could you see where the problem is? the code runs fine if the days is set to 1, but if i put all the values to Zero i get 6:28:9 and then it starts to countdown. i stripped the previous code which includes an encoder + pushbutton a menu and a st7735 tftView attachment Test_CountdownMillisAG.ino
best regards
Bastiaan
i am trying to build a simple countdown with a teensy3.2 with the millis function: but somehow the code is not responding properly could you see where the problem is? the code runs fine if the days is set to 1, but if i put all the values to Zero i get 6:28:9 and then it starts to countdown. i stripped the previous code which includes an encoder + pushbutton a menu and a st7735 tftView attachment Test_CountdownMillisAG.ino
best regards
Bastiaan
Code:
Int long Days = 1;
Int long Hours = 0;
Int long Min = 0;
Int long Sec_add = 0;
unsigned long Sec;
unsigned long DisplaySec;
unsigned long DisplayMin;
unsigned long DisplayHours;
unsigned long DisplayDays;
unsigned long startTime;
unsigned long oneSecond = 1000UL;
void Setup()
{
Sec = Sec_add + round(60 * Min) + round(60 * 60 * Hours) + round(60 * 60 * 24 * Days);
}
void Loop()
{
if (millis() - startTime >= oneSecond)
{
Sec--;
startTime += oneSecond;
if (Sec <= 0)
DisplayDays = Sec / 86400;
DisplayHours = Sec / 3600;
DisplayMin = Sec / 60;
DisplaySec = Sec % 60;
}
Serial.print((DisplayHours % 60) % 60);
Serial.print(":");
Serial.print(DisplayMin % 60);
Serial.print(":");
Serial.print(DisplaySec);
}
Last edited: