Help with timing function
first here code:
hopefully that's enoug going, can post whole sketch it's lot. part i'm wondering if can on the:
as can see when time reached warning function run sounds audible alarm (a tone speaker). alarm function called every x number of seconds/minutes/etc, defined warningbeepinterval1. set sounds tone every minute (warningbeepinterval1 = 60000;).
this works great - timer counts down , reaches 5 min mark tone sounded every minute
the issue i'm having if pause button pressed if (digitalread(pausesw) == low) program goes pause state causes main main timer:
to stop running. when start button pressed goes count down function - if you've reached 5 minute mark , tones have started sound when pause button pressed when comes out of pause tones out of sync main timer. still sound every minute but, again not in sync main timer.
i know has fact i'm using millis() keep track of time passed , in pause state it's still running if pause 2 minutes , un-pause if (millis() - lastwarningtime > warningbeepinterval1) { true , runs you'd expect to.
i'm @ loss on how resolve , hoping can ideas. if need more info, ro whole sketch, let me know. thanks.
code: [select]
void f_countdown() {
if (clearlcd == true) {
lcd.clear();
clearlcd = false;
}
lcdbacklight(0, 0, 255); // blue
lcd.setcursor(2, 0);
lcd.print("time started:");
// if second has passed subtract allowedplaytime
if (millis() - currentmillis > 1000) {
allowedplaytime = allowedplaytime - 1000;
currentmillis = millis();
f_timedisplay();
// if there less 5 minutes of playtime left start sounding audible alarm @ interval defined.
if (allowedplaytime <= 300000) { // 5 min
if (millis() - lastwarningtime > warningbeepinterval1) {
f_warning1();
}
// or if there less 10 seconds of playtime left start sounding audible alarm @ interval defined.
else if (allowedplaytime <= 10000) { // 10 seconds
if (millis() - lastwarningtime > warningbeepinterval2) {
f_warning2();
}
}
}
}
if (digitalread(pausesw) == low) { // logic inverted since we're using internal resistors. when button pressed pin goes low, when not pressed it's high.
lcd.clear();
state = s_pause;
}
if (allowedplaytime == 0) {
lcd.clear();
state = s_timeup;
}
}
hopefully that's enoug going, can post whole sketch it's lot. part i'm wondering if can on the:
code: [select]
if (allowedplaytime <= 300000) { // 5 min
if (millis() - lastwarningtime > warningbeepinterval1) {
f_warning1();
as can see when time reached warning function run sounds audible alarm (a tone speaker). alarm function called every x number of seconds/minutes/etc, defined warningbeepinterval1. set sounds tone every minute (warningbeepinterval1 = 60000;).
this works great - timer counts down , reaches 5 min mark tone sounded every minute
the issue i'm having if pause button pressed if (digitalread(pausesw) == low) program goes pause state causes main main timer:
code: [select]
if (millis() - currentmillis > 1000) {
allowedplaytime = allowedplaytime - 1000;
currentmillis = millis();
f_timedisplay();
to stop running. when start button pressed goes count down function - if you've reached 5 minute mark , tones have started sound when pause button pressed when comes out of pause tones out of sync main timer. still sound every minute but, again not in sync main timer.
i know has fact i'm using millis() keep track of time passed , in pause state it's still running if pause 2 minutes , un-pause if (millis() - lastwarningtime > warningbeepinterval1) { true , runs you'd expect to.
i'm @ loss on how resolve , hoping can ideas. if need more info, ro whole sketch, let me know. thanks.
when button pressed again, you'll want set lastwarningtime in sync main timer. hard how exactly, without seeing full code.
Arduino Forum > Using Arduino > Project Guidance > Help with timing function
arduino
Comments
Post a Comment