Stopping time.h?

Hello programmers,

I'm a novice programmer, and using the time.h library to make a little timer (that counts upwards) with a 4-digit 7-segmented display. It works fine but now I've added a button to stop the the timer and then restart it without going back to 00:00. Since the time.h library seems to just pull the elapsed time since the program began, and I don't see a command to stop the library timer, i've been trying to do it through the code but have been unable so far. Any suggestions on how to do this would be appreciated. Thanks to any who respond.

If you are just using the Arduino's 16Mhz clock to keep time you could just use millis() without any need for a library. Look at the Blink Without Delay example code.

If you want to pause the timer and then continue where you left off you need to increment the timer with the difference beween the value of millis() when you restart the timer and the current value.

Millis() starts at 0 when the Arduino resets.
After 20 seconds it will have got to 20,000

Suppose you stop the clock display at 20 for 15 seconds.

When the clock is restarted millis() will be at 35,000 but you don't want to display 35 on the display - it should stay at 20.
A second later millis() will be at 36,000 and you want the display show 21 (or 20 + 1). The extra 1 comes from the difference between 35,000 and 36,000.

Hope that makes sense.

...R

Thanks so much Robin2. I really appreciate you taking the time to help. I'll give your suggestions a try!