6v6gt:
Clocktime = Clocktime - (Tenhours * 36000000) ;
better for numbers to big for a 16bit integer:
Clocktime = Clocktime - (Tenhours * 36000000UL) ;
If i understand correctly the UL forces it in a unsigned long right ? ( continued below)
lesept:
The test should always be true, as millis() is always strictly positive, as soon as the first millisecond passes. So you don't need it.
Here is what I'd suggest:
unsigned long Clocktime;
byte Tenhours, Hours, Tenminutes, Minutes, TenSeconds, Seconds;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
Clocktime = millis();
Tenhours = Clocktime / 36000000UL;
Clocktime = Clocktime - (Tenhours * 36000000UL) ;
Hours = Clocktime / 3600000UL;
Clocktime = Clocktime - (Hours * 3600000UL);
Tenminutes = Clocktime / 600000UL;
Clocktime = Clocktime - (Tenminutes * 600000UL);
Minutes = Clocktime / 60000UL;
Clocktime = Clocktime - (Minutes * 60000UL);
TenSeconds = Clocktime / 10000UL;
Clocktime = Clocktime - (TenSeconds * 10000UL) ;
Seconds = Clocktime / 1000UL;
// above calculation makes it so that minutes won't exceed 60 etc.
lcd.setCursor(15, 1);
lcd.print(Seconds);
lcd.setCursor (14, 1);
lcd.print(TenSeconds);
lcd.setCursor(13, 1);
lcd.print(Minutes);
lcd.setCursor(12, 1);
lcd.print(Tenminutes);
lcd.setCursor(11, 1);
lcd.print(Hours);
lcd.setCursor(10, 1);
lcd.print(Tenhours);
delay (1000);
}
Although I'm not sure that the division of UL numbers can correctly fit in bytes. If the display is not correct, you can change this line :
`byte Tenhours, Hours, Tenminutes, Minutes, TenSeconds, Seconds;`to`unsigned long Tenhours, Hours, Tenminutes, Minutes, TenSeconds, Seconds;`
If you see some latency in the change of the seconds, it may be due to cumulative precision errors in the delay and the additional time of the rest of the code. You then can change
`delay (1000);`to some shorter value such as `delay (200);`
All the tenminutes, minutes and such are already defined as unsigned longs at the beginning of the program, can be found @ the url i provided, and it works so....
put delay on a second since i found it annoying when the display switches numbers al the time, every second seems to be acceptable.
wouldn't the latency be greater if the calculation was performed multiple times per second as opposed to once every second ?
You are right about the millis>0 thing though. will probably take it out.
still looking for a way to reset every 24 hours.