lcd.print(millis()/1000);
this code counts off in seconds
how can I set it back to 0 seconds
what i'm trying to do is have the seconds counting off and when it gets to a minute it prints it to LCD, then increases to the next minute...
lcd.print(millis()/1000);
this code counts off in seconds
how can I set it back to 0 seconds
what i'm trying to do is have the seconds counting off and when it gets to a minute it prints it to LCD, then increases to the next minute...
unsigned long startTime = 0;
lcd.print((millis()-startTime)/1000);
startTime = millis(); // Reset the 'timer' to zero
thank you John
Something to bear in mind is that the millis will overflow, ie reset back to zero, after approx 50 days.
This may well be not relevant depending on how long your code will be running and what it's doing, but if it is you'll need to cater for it.
Gunney_Plym:
Something to bear in mind is that the millis will overflow, ie reset back to zero, after approx 50 days.This may well be not relevant depending on how long your code will be running and what it's doing, but if it is you'll need to cater for it.
I checked the math and if you do the "(millis() - startTime)" calculation, both being unsigned long, the math works out. As long as you are not trying to measure an INTERVAL longer than 50 days it will work.
Example:
The start time is 0xFFFFFF00 (256 milliseconds before rollover).
512 milliseconds later millis() has overflowed by 256 and is now 0x00000100.
Subtracting 0xFFFFFF00 from 0x00000100 leaves you with 0x00000200 which equals 512, the elapsed interval!
MAGIC! ![]()
I'll only be running the program for less then 24 hours at a time....thanks all for your help