OK. So if your code is still in state
WaitForTimerOFF_PeriodToEnd
or in state WaitForTimerONTime_End
you add an if-condition that checks if mode was changed to Auto
and if this condition results in true
you change the state-variable.
As the timing is done non-blocking
your loop runs at high speed.
The state WaitForTimerOFF_PeriodToEnd is entered thousands of times
each time checking
if (currentMillis - TimerModeOnTimeStamp >= SwitchOnDurationInTimerMode) {
and only when MyStateVariable changes to a new state the code inside this state gets executed
So you add
if (timermode == 0) {
MyStateVariable = CheckValue;
}
inside the
case WaitForTimerONTime_End:
and inside the
case WaitForTimerOFF_PeriodToEnd:
If you want to have this behaviour from switching from automode to timermode too you add the appropriate conditions their too
Your code is a very good example how state-machines "simplify" things
compared to add more and more if-conditions and boolean variables
"simplifly" in double-hyphens as this programming-technique is somehow advanced.
best regards Stefan