So the wanted functionality is you have a constant sequence of steps switching some IO-pins HIGH/LOW after different periods of time.
and whenever you press the button stop the sequence
This is best coded using lines of code that build a so called state-machine
state 1: wait 5000 milliseconds have passed by
state 2: switch motorbrake HIGH
state 3: wait 4000 milliseconds have passed by
state 4: switch switch motor-brake LOW
state 5: wait until 3000 milliseconds have passed by
state 6: switch e14 HIGH
state 7: wait 2000 milliseconds have passed by
state 8: switch e14 LOW
state 9: wait 4000 milliseconds have passed by
state 10: switch motorbrake HIGH
state 11: wait 4000 milliseconds have passed by
state 12: switch switch motor-brake LOW
state 13: wait 2000 milliseconds have passed by
state 14: switch e12 HIGH
state 15: wait 13000 milliseconds have passed by
state 16: switch e12 LOW and increase variable counter by one
writing this code uses the switch-case-break; statement
the break; is very important to make it work as intended
In your case The conditions to proceed to the next state is
- either immitiately change to next state
or - change to the next state after a number of milliseconds have passed by
I have written a tutorial about state-machines
best regards Stefan