AndrewMascolo / CountUpDownTimer

MIT License
28 stars 20 forks source link

time stop at 15sec #8

Open fofito13 opened 8 years ago

fofito13 commented 8 years ago

i use this script in arduino nano: `#include CountUpDownTimer T(DOWN);

void setup() { Serial.begin(9600); //pinMode(6, INPUT_PULLUP); pinMode(botonPin1, INPUT); T.SetTimer(0,0,20); T.StartTimer(); }

void loop() { T.Timer(); // run the timer

//Serial.println("run \r\n"); if (T.TimeHasChanged() ) // this prevents the time from being constantly shown. { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.println(T.ShowSeconds()); }

}`

at 15 seconds the counter stop. please help me!!

AndrewMascolo commented 8 years ago

The answer is among the other comments. It's a line of code you need to fix.

Sent from my iPhone

On Mar 1, 2016, at 7:36 AM, fofito13 notifications@github.com wrote:

i use this script: `#include

CountUpDownTimer T(DOWN); const int botonPin1 = 5; int estadoBoton1 = 0; bool estado = 1;

void setup() { Serial.begin(9600); //pinMode(6, INPUT_PULLUP); pinMode(botonPin1, INPUT); T.SetTimer(0,0,20); T.StartTimer(); Serial.println("inicio \r\n"); }

void loop() { T.Timer(); // run the timer

//Serial.println("run \r\n"); if (T.TimeHasChanged() ) // this prevents the time from being constantly shown. { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.println(T.ShowSeconds()); }

}`

at 15 seconds the counter stop. please help me!!

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

fofito13 commented 8 years ago

It works right!! Thank you very much for the reply and the fabulous library

MeisterMax commented 8 years ago

Hmmm... I've just the same problem. My timer stops at 15 seconds, no matter whether it is 2:15, 5:15 or 0:15. Moreover, if I set the timer to, say, 0:14, it doesn't even start to count down. I don't quite get though what the solution is... what other comment are you refering to? Thanks in advance, Max

Here's my code, by the way:

include "CountUpDownTimer.h"

include "LiquidCrystal.h"

CountUpDownTimer T(DOWN); LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

lcd.begin(16, 2); T.SetTimer(0, 2, 45); T.StartTimer();

}

void loop() {

T.Timer();

lcd.setCursor(0, 0); lcd.print(T.ShowSeconds()); lcd.setCursor(0, 1); lcd.print(T.ShowMinutes());

}

Rather straightforward, I'd have thought... But probably I'm just too stupid :)

AndrewMascolo commented 8 years ago

The answer is in the other comments

Sent from my iPhone

On Mar 13, 2016, at 10:39 AM, MeisterMax notifications@github.com wrote:

Hmmm... I've just the same problem. My timer stops at 15 seconds, no matter whether it is 2:15, 5:15 or 0:15. Moreover, if I set the timer to, say, 0:14, it doesn't even start to count down. I don't quite get though what the solution is... what other comment are you refering to? Thanks in advance, Max

Here's my code, by the way:

include "CountUpDownTimer.h"

include "LiquidCrystal.h"

CountUpDownTimer T(DOWN); LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

lcd.begin(16, 2); T.SetTimer(0, 2, 45); T.StartTimer();

}

void loop() {

T.Timer();

lcd.setCursor(0, 0); lcd.print(T.ShowSeconds()); lcd.setCursor(0, 1); lcd.print(T.ShowMinutes());

}

Rather straightforward, I'd have thought... But probably I'm just too stupid :)

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

MeisterMax commented 8 years ago

Am I blind? Which other comments? I only see five including the one I'm writing right now... sorry...

AndrewMascolo commented 8 years ago

Sorry about that. I found the issue and I will post the fix soon. The problem was a missing operator ( ! ) in the TimeCheck function. All you need to do is change _type to !_type. Save it and it should work.

Sent from my iPhone

On Mar 13, 2016, at 1:44 PM, MeisterMax notifications@github.com wrote:

Am I blind? Which other comments? I only see five including the one I'm writing right now... sorry...

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

MeisterMax commented 8 years ago

Wow, thank you! It works. And, as fofito13 has already said, awesome library. Max

AndrewMascolo commented 8 years ago

Thank you. I fixed the bug in the library and re-uploaded it

Sent from my iPhone

On Mar 13, 2016, at 5:05 PM, MeisterMax notifications@github.com wrote:

Wow, thank you! It works. And, as fofito13 has already said, awesome library. Max

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

MiroHlad commented 8 years ago

Hi if TimeCheck() should return True if the time is equal to particular time The code should be updated as follows: if(_type) return (Clock == TC); else
return (Clock == TC ); } I tested and It works good to me. Thanks Miro

AndrewMascolo commented 8 years ago

What happens if you are doing something (or decide to put in a delay) and go past the time you set for? Then == doesn't work.

Sent from my iPhone

On May 26, 2016, at 6:41 PM, MiroHlad notifications@github.com wrote:

Hi if TimeCheck() should returns true if the time is equal to particular time shouldn't be the code like that if(_type) return (Clock == TC); else

return (Clock == TC ); } It works good to me. Thanks Miro

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

MiroHlad commented 8 years ago

Hi agree with you that for delays is == unusable. I need to check the time a lot of times, but when I used <= . It returns True on a first check and than keep the True, if I do next check I always receive 1. Maybe I just dont understand the timecheck function and I should use it different way. When I changed the logic to == it works as I need. I simplified the example how I use it - see below - in my script I dont use the exact time values in check function but variables,

Anyway I like your library, It makes my life easier. :) THANK YOU

if (T.TimeCheck(0, 0, 27)) { turnLR = 1;
// Serial.println(T.TimeCheck(0, 0, 27)); } else if (T.TimeCheck(0, 0, 20)) { turnLR = 0; // Serial.println("TimeCheck(0, 0, 20)"); } else if (T.TimeCheck(0, 0, 15)) { turnLR = 2; // Serial.println("TimeCheck(0, 0, 15)"); } else if (T.TimeCheck(0, 0, 5)) { turnLR = 0; // Serial.println("TimeCheck(0, 0, 5)"); }

AndrewMascolo commented 8 years ago

Do a print of TimeCheck at those times and see if you always see true.

I'm betting if you invert the logic i.e. If( !T.TimeCheck(0,0,27)) If (!T.TimeCheck(0,0,20)) . . .

You should see the code working.

Or if you want you can create a new method for yourself and I will add it in later to the library.

I would call it "ExactTimeCheck(...)"

Sent from my iPhone

On May 27, 2016, at 3:24 PM, MiroHlad notifications@github.com wrote:

Hi agree with you that for delays is == unusable. I need to check the time a lot of times, but when I used <= . It returns True on a first check and than keep the True, if I do next check I always receive 1. Maybe I just dont understand the timecheck function and I should use it different way. When I changed the logic to == it works as I need. I simplified the example how I use it - see below - in my script I dont use the exact time values in check function but variables,

Anyway I like your library, It makes my life easier. :) THANK YOU

if (T.TimeCheck(0, 0, 27)) { turnLR = 1;

// Serial.println(T.TimeCheck(0, 0, 27)); } else if (T.TimeCheck(0, 0, 20)) { turnLR = 0; // Serial.println("TimeCheck(0, 0, 20)"); } else if (T.TimeCheck(0, 0, 15)) { turnLR = 2; // Serial.println("TimeCheck(0, 0, 15)"); } else if (T.TimeCheck(0, 0, 5)) { turnLR = 0; // Serial.println("TimeCheck(0, 0, 5)"); }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

MiroHlad commented 8 years ago

Thank you for your fast respons and your time. Currently working on some project and it is close to end. I like the ExactTimeCheck(...), but I will give it a time till I finished it, to be sure that the right way. Thank you again. Miro