Closed Mannelito closed 9 years ago
I advise you not use delays when using this library. As a delay stops anything else from happening until the delay is complete. Undoubtedly it is causing the issue you are seeing as micros() is running in the background but the rest of the library cannot.
Though I hadn’t come across that issue before, I will however look into it and if it is needed then I will make the correction to the function and add your name to the top of the library under Helpful Corrections by…
Thank you.
From: Mannelito [mailto:notifications@github.com] Sent: Thursday, May 14, 2015 10:59 AM To: AndrewMascolo/CountUpDownTimer Subject: [CountUpDownTimer] Counting continues in background when paused. (#1)
Hey Andrew,
I've been applying your code in a project and had quite some issues when pausing the timer. Using the example file to demonstrate the issue, you'll see that the timer tries to catch up when resuming:
int i = 0; CountUpDownTimer T(UP);
void setup() { Serial.begin(115200); T.StartTimer(); }
void loop() { T.Timer(); // run the timer
while (i < 5) { delay(1000); i++; T.PauseTimer(); } T.ResumeTimer();
if (T.TimeHasChanged() ) // this prevents the time from being constantly shown. { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.print(T.ShowSeconds()); Serial.print(":"); Serial.print(T.ShowMilliSeconds()); Serial.print(":"); Serial.println(T.ShowMicroSeconds()); // This DOES NOT format the time to 0:0x when seconds is less than 10. // if you need to format the time to standard format, use the sprintf() function. } }
Adjusting the following exerpt in the library file:
void ResumeTimer() // You can resume the timer if you ever stop it. {
if (Paused == true) { Paused = false; time = micros(); }
Yielded a result where the timer didn't try to catch up. Not sure if the timer is intended to work as originally coded, but I felt that this was more intuitive.
Best regards /Manne
— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/1 .Image removed by sender.
File updated, 5/14/2015
Thanks for the quick feedback, I'll keep the delay issue in mind and see if I can make some improvements in my program.
Nitpicking Removing the "if (Paused == true)" condition in the function will require the end user to add conditions of their own to monitor the transition from paused to resumed in order to avoid the constant loop of "time = micro". I think the package would be more intuitive for novices such as me with a monitored transition already prepared. End nitpicking
Thanks for a nice program! /Manne
Hey Andrew,
I've been applying your code in a project and had quite some issues when pausing the timer. Using the example file to demonstrate the issue, you'll see that the timer tries to catch up when resuming:
include
int i = 0; CountUpDownTimer T(UP);
void setup() { Serial.begin(115200); T.StartTimer(); }
void loop() { T.Timer(); // run the timer
while (i < 5) { delay(1000); i++; T.PauseTimer(); } T.ResumeTimer();
if (T.TimeHasChanged() ) // this prevents the time from being constantly shown. { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.print(T.ShowSeconds()); Serial.print(":"); Serial.print(T.ShowMilliSeconds()); Serial.print(":"); Serial.println(T.ShowMicroSeconds()); // This DOES NOT format the time to 0:0x when seconds is less than 10. // if you need to format the time to standard format, use the sprintf() function. } }
Adjusting the following exerpt in the library file:
Yielded a result where the timer didn't try to catch up. Not sure if the timer is intended to work as originally coded, but I felt that this was more intuitive.
Best regards /Manne