-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
how do i close a timer? #9
Comments
The in / at / every functions return the Task. From the README: To cancel a Task auto task = timer.in(delay, function_to_call);
timer.cancel(task); so: auto task = delay_timer.every(1000, bomb_armed);
delay_timer.cancel(task); There's also a cancel example in examples/full/full.ino |
arduino ide replies that
task is not defined in this scope ... ore something like that.
I bypassed the problem defining Timer<1, millis> delay_timer
and running the timer with:
auto task_delay = defuse_delay_timer.every(1000, function_to_call);
results in compiles ok.
…On Fri, 13 Dec 2019 at 08:45, Michael Contreras ***@***.***> wrote:
The *in / at / every* functions return the *Task*. From the README:
To *cancel* a *Task*
auto task = timer.in(delay, function_to_call);
timer.cancel(task);
so:
auto task = delay_timer.every(1000, bomb_armed);
delay_timer.cancel(task);
There's also a cancel example in examples/full/full.ino
<https://github.com/contrem/arduino-timer/blob/master/examples/full/full.ino#L66>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9?email_source=notifications&email_token=AAK4JWUPSM7WGMHBKDZIPEDQYM4TPA5CNFSM4J2CQNQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGZF6WA#issuecomment-565337944>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK4JWX4WKPU2PKA7GZX4JTQYM4TPANCNFSM4J2CQNQA>
.
--
Sourceforge: https://sourceforge.net/u/allegfede/
YouTube Channel: https://www.youtube.com/c/v1p3rslab
VIMEO HD videos: http://www.vimeo.com/user1912745/videos
|
Without seeing your code I am unable to diagnose your potential issue. Does examples/full/full.ino compile with your setup? |
He is right though. There is definitely an issue with cancel. If I call cancel inside a function, I get errors. I literally have to setup the timer again then call the cancel immediately to cancel both instances. This has to be issue or your example is not very clear. Using this in a real world scenario, you're not going to immediately call for a cancel after setting the timer like in your example. Needs to be more clear. |
Please provide an example of the errors, and example code that isn't working properly, to help identify the issue you're experiencing. |
Running into the same issue - is there a way to define the task variables on the root scope without instantiating them? Otherwise, there is no way to cancel them from within another callback function call (unless I'm missing something)
|
Yes. In your example, replace: auto ledEvent;
auto countdownEvent;
auto startRoutineEvent; With Timer<>::Task ledEvent;
Timer<>::Task countdownEvent;
Timer<>::Task startRoutineEvent; You get an error because you can't use auto without an initializer. Note that the Timer<>::Task constructor must match the Timer template if it wasn't created as the default timer. Let me know if this helps, and thank you for providing example code and error messages. |
i made a timer with:
auto delay_timer = timer_create_default();
and cannot terminate it using:
delay_timer.cancel();
timer is started with:
delay_timer.every(1000, bomb_armed);
seems he need the "task", but cannot find a way to define this task ...
The text was updated successfully, but these errors were encountered: