Understanding state machine example

If you have the stamina to wade through the long discussion in the link I posted you will see that the best way to prepare for the next time check is with

StateStartTime += StateDuration

rather than

StateStartTime=millis();

This is because you can't be certain that the code which (in your case) calls ChangeState() always does so at precisely the right time. Adding the duration means that successive intervals are always referenced to the original starting time.

...R