CountUpDownTimer icon indicating copy to clipboard operation
CountUpDownTimer copied to clipboard

add a method to change end time without reset counter

Open fireport opened this issue 10 years ago • 5 comments

For my sketch i need to increment/decrement end timer but when i SetTimer with new value the remaing time counter reset. Can you add a method for this task ? Many thanks in advance

example case 0xFFC23D: Timer_Duration += 10; T.SetTimer(Timer_Duration * 60); break; case 0xFF02FD: if (Timer_Duration > 10) { Timer_Duration -= 10; T.SetTimer(Timer_Duration * 60); } break;

fireport avatar Nov 27 '15 15:11 fireport

Show me your code

Sent from my iPhone

On Nov 27, 2015, at 10:59 AM, Demetrio Condello [email protected] wrote:

For my sketch i need to increment/decrement end timer but when i SetTimer with new value the remaing time counter reset. Can you add a method for this task ? Many thanks in advance

— Reply to this email directly or view it on GitHub.

AndrewMascolo avatar Nov 27 '15 17:11 AndrewMascolo

The idea behind SetTimer is you set a time and it counts down from that. If you want to add or subtract time and have it continue from where it left off then you need to subtract the current time from your Timer_Duration.

I will add in a method to return the current total seconds ie. "Clock" then all you need to do is subtract your duration from that method.

AndrewMascolo avatar Nov 27 '15 22:11 AndrewMascolo

Updated the library. New method added. ShowTotalSeconds()

AndrewMascolo avatar Nov 27 '15 22:11 AndrewMascolo

Thanks Andrew ! Can you solve me another issue with myr code ? When i use SetTimer with the new value i obtain strange numbers... This is the problematic portion of code

   Serial.println(T.ShowHours());
    Serial.println(T.ShowMinutes());
    Serial.println(Timer_Duration);
    T.SetTimer(Timer_Duration*60-T.ShowTotalSeconds());

    Serial.println(T.ShowHours());
    Serial.println(T.ShowMinutes());
    Serial.println(Timer_Duration);

and this is the output:

7 59 490 0 ?????? 10 ?????? 490

Thanks

2015-11-27 23:49 GMT+01:00 AndrewMascolo [email protected]:

Updated the library. New method added. ShowTotalSeconds()

— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/3#issuecomment-160223926 .

fireport avatar Dec 04 '15 19:12 fireport

You need to use parenthesis. Now is the new time greater than the old time or smaller. Your time will be strange if you have a negative number.

Sent from my iPhone

On Dec 4, 2015, at 2:45 PM, Demetrio Condello [email protected] wrote:

Thanks Andrew ! Can you solve me another issue with myr code ? When i use SetTimer with the new value i obtain strange numbers... This is the problematic portion of code

Serial.println(T.ShowHours()); Serial.println(T.ShowMinutes()); Serial.println(Timer_Duration); T.SetTimer(Timer_Duration*60-T.ShowTotalSeconds());

Serial.println(T.ShowHours()); Serial.println(T.ShowMinutes()); Serial.println(Timer_Duration);

and this is the output:

7 59 490 0 ?????? 10 ?????? 490

Thanks

2015-11-27 23:49 GMT+01:00 AndrewMascolo [email protected]:

Updated the library. New method added. ShowTotalSeconds()

— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/3#issuecomment-160223926 .

— Reply to this email directly or view it on GitHub.

AndrewMascolo avatar Dec 04 '15 20:12 AndrewMascolo