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

asked Jan 6, 2020 at 10:59

1 Answer 1

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.