Z
First, the hours algorithm must look like:for (char h = 0; h < 24; h++) {
for (char m = 0; m < 60; m++) {
for (char s = 0; s < 60; s++) {
for (int ms = 0; ms < 1000; ms++) {
lcd.setCursor(0, 0);
lcd.print(h, DEC);
lcd.print(":");
lcd.print(m, DEC);
lcd.print(":");
lcd.print(s, DEC);
lcd.print(".");
lcd.print(ms, DEC);
}
}
}
}
Secondly, with the withdrawal of, for example, hours, there will be 1.2.3... while it would be desirable to see 01, 02, 03. I mean, for hours insteadlcd.print(h, DEC);
I need to write.if (h < 10)
lcd.print('0');
lcd.print(h, DEC);
a for a millisecond.if (ms < 10)
lcd.print('0');
if (ms < 100)
lcd.print('0');
lcd.print(ms, DEC);
Finally, to make sure the clock goes, the milliseconds should be counted not in the cycle but using the function. millis()♪ Like this:void loop()
{
unsigned long time = millis();
unsigned long hours = time / 3600000L;
hours = hours % 24;
time = time % 3600000L;
unsigned long minutes = time / 60000;
time = time % 60000;
unsigned long seconds = time / 1000;
unsigned long milliseconds = time % 1000;
lcd.setCursor(0, 0);
lcd.print(hours, DEC);
lcd.print(":");
lcd.print(minutes, DEC);
lcd.print(":");
lcd.print(seconds, DEC);
lcd.print(".");
lcd.print(milliseconds, DEC);
}