I am currently doing a school project. There you have to program a stopwatch with the Arduino. I wrote a program where millis starts. But when I press my start button, millis don‘t start from 0. Has someone an idea? Please let me know.
Ps: I‘m German, so I‘m sorry for my bad English enter image description here
1 Answer 1
You don't. Instead you just remember what millis()
was when you pressed your start button, then subtract that from whatever millis()
is showing at any other point in the future.
-
I‘ve just added a picture of my program, maybe you‘re able to take a lookLaurentien– Laurentien2020年01月06日 11:11:16 +00:00Commented Jan 6, 2020 at 11:11
-
3@Laurentien Please... don't post photographs of code. Post the actual code.Majenko– Majenko2020年01月06日 11:45:58 +00:00Commented Jan 6, 2020 at 11:45
-
BTW: millis() returns an unsigned long. That will make a difference after 24 days of continuous running. And it will allow running forever, even when that unsigned long will roll over.DataFiddler– DataFiddler2020年01月06日 12:14:49 +00:00Commented Jan 6, 2020 at 12:14
-
@DataFiddler but doing
stopmillis-startmillis
will always return the correct value if the time between start and stop is less than the 24-day rollover.ratchet freak– ratchet freak2020年01月06日 13:10:39 +00:00Commented Jan 6, 2020 at 13:10 -
It's a 49+ day rollover. unsigned long lets millis() return from 0 to 4,294,967,295 mS. x 1 second/1000mS, x 1 minute/60 seconds, x 1 hour/60 minutes, x 1 day/24 hours = 49.59 daysCrossRoads– CrossRoads2020年01月06日 15:10:23 +00:00Commented Jan 6, 2020 at 15:10