Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reseting the timer #86

Open
dave5992 opened this issue Aug 28, 2023 · 3 comments
Open

reseting the timer #86

dave5992 opened this issue Aug 28, 2023 · 3 comments

Comments

@dave5992
Copy link

It would be great if we could get a reset funtion

@philj404
Copy link
Contributor

philj404 commented Sep 1, 2023

I'm not sure what you mean by a 'reset function'.

Does timer.cancel(aTaskId); do what you want?

@dave5992
Copy link
Author

dave5992 commented Dec 9, 2023

if timer.cancel(); resets the time to 0 then yes.

@philj404
Copy link
Contributor

philj404 commented Dec 9, 2023

By default the timer uses millis() to determine the current time (time since last hard reset). The timer only reads the value of millis() -- never modifies it directly. I don't know if there's a way to reset it to zero without a hard reset.

If millis() starts returning earlier values, the timer will get confused about when a pending task should come due.

timer.cancel() just clears all pending tasks. That's probably good enough to do what you need. The timer tasks don't particularly care what value millis() returns, they just check if millis() has increased beyond the delay requested (relative to when the task was created).

(This is probably not worth the effort, but...)
You can substitute your own function (and do your own resetting) instead of using the default millis(). See an example simMillis() in https://github.com/contrem/arduino-timer/blob/master/extras/tests/timerTest/timerTest.ino. I use it to run tests without actually waiting for millis() to elapse/increment over seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants