Hi all,
I have a counter in my program that counts up in seconds, and can count up to several hours. I then print this total on an LCD screen, and I want to print it in a clock format: [HH:MM:SS].
My current solution works, but it doesn’t preserve 2 numbers in each slot at all times - so if it’s 64 seconds in, it prints 0:1:4, and at 1012 seconds in, it prints 0:16:52. This is readable to me, but not ideal. How can I preserve 2 numbers in each slot at all times?
At the moment, I’m doing this:
void format (unsigned long t)
{
unsigned long h = t / 3600;
t = t % 3600;
int m = t / 60;
int s = t % 60;
lcd.setCursor(0,1);
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);
}
Thanks!