Hey,
I'm messing with this function I found a while back to display milliseconds in a countdown timer and it does something strange when I feed it 6 hours it displays 00:12:14 instead of 06:00:00. Anyone have any ideas, I didn't write it I found it online.
Cheers
Here is the code.
I'm messing with this function I found a while back to display milliseconds in a countdown timer and it does something strange when I feed it 6 hours it displays 00:12:14 instead of 06:00:00. Anyone have any ideas, I didn't write it I found it online.
Cheers
Here is the code.
Code:
void print_time(unsigned long t_milli)
{
char buffer[20];
int days, hours, mins, secs;
int fractime;
unsigned long inttime;
inttime = t_milli / 1000;
fractime = t_milli % 1000;
// inttime is the total number of number of seconds
// fractimeis the number of thousandths of a second
// number of days is total number of seconds divided by 24 divided by 3600
days = inttime / (24*3600);
inttime = inttime % (24*3600);
// Now, inttime is the remainder after subtracting the number of seconds
// in the number of days
hours = inttime / 3600;
inttime = inttime % 3600;
// Now, inttime is the remainder after subtracting the number of seconds
// in the number of days and hours
mins = inttime / 60;
inttime = inttime % 60;
// Now inttime is the number of seconds left after subtracting the number
// in the number of days, hours and minutes. In other words, it is the
// number of seconds.
secs = inttime;
// Don't bother to print days
//sprintf(buffer, "%02d:%02d:%02d.%03d", hours, mins, secs, fractime);
sprintf(buffer, "%02d:%02d:%02d", hours, mins, secs);
lcd.print(buffer);
}