0

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

2

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.

| improve this answer | |
  • I‘ve just added a picture of my program, maybe you‘re able to take a look – Laurentien Jan 6 at 11:11
  • 3
    @Laurentien Please... don't post photographs of code. Post the actual code. – Majenko Jan 6 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 Jan 6 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 Jan 6 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 days – CrossRoads Jan 6 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.