I wrote an extended demo based on the principles of the Blink Without Delay example sketch here. It also uses global variables to manage timing so it may be useful to study it in parallel with the code you have.
In the code you already have "PulseLength=ChangeState();" is the line that calls the ChangeState() function.
...R