AndrewMascolo / CountUpDownTimer

MIT License
28 stars 20 forks source link

add a method to change end time without reset counter #3

Open fireport opened 8 years ago

fireport commented 8 years ago

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;

AndrewMascolo commented 8 years ago

Show me your code

Sent from my iPhone

On Nov 27, 2015, at 10:59 AM, Demetrio Condello notifications@github.com 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 commented 8 years ago

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 commented 8 years ago

Updated the library. New method added. ShowTotalSeconds()

fireport commented 8 years ago

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 notifications@github.com:

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 .

AndrewMascolo commented 8 years ago

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 notifications@github.com 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 notifications@github.com:

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.