Closed Tsjompie closed 4 years ago
Timers are reset upon every state change. So in this case in IDLE it seems the first timer expires, the display is updated and the state jumps back to IDLE. Both timers are reset, then the first timer will again expire first. The second never becomes active.
To solve this you could use two idle states. One with a 700 timer and one with a 100 timer.
IDLE1 switches to IDLE2 on timer(700) IDLE2 switches to IDLE1 on timer(100)
ENT_IDLE2 calls updatedisplay ENT_IDLE1 calls updatevalues
Remember that a timer is always relative to the state, it counts from the last state change.
THANKS!
Hi @tinkerspy: your suggestion implies the timers run consecutive. Based on the above example, the updatedisplay runs every 800 ms as that state also depends on the expiry of the 100 ms timer.
Just finish the SM dealing with this, but: Would there also be a way to make those timers independent from each other?
Just asking.
Tsjompie
The timers objects are always relative to the last state change, but there's no reason you couldn't store your own timestamps and compare them to millis().
Something like this?
case EVT_TMRDISPLAY:
if ( millis() - last_tmr_display > tmr_display_interval ) {
last_tmr_display = millis();
return 1;
}
return 0;
case EVT_TMRVALUES:
if ( millis() - last_tmr_values > tmr_values_interval ) {
last_tmr_values = millis();
return 1;
}
return 0;
💪
LS,
I added 2 timers in a state machine. When one of the timers expires it looks like both the timers are reset. This results in the situation the timer with the smallest duration is executed, the other one seems to get a reset and isn't executed at all.
What do I oversee here? How to make both times work using a single state machine?
Thanks for the heads-up.
Tsjompie
I got the following h file:
and this cpp file:
The ino has this:
The debugger shows this:
Thanks again! Any push towards a solution is highly appreciated.