This requirement cries for using a state-machine.
A state-machine is a concept build with the switch-case-break; - structure which does mutually exclusive execute multiple parts of code each part of the code executing mutual exclusive.
This gives an easy to follow code-structure with a minimised number of if-conditions and flag-variables can be avoided most of the time.
I'm not willing to transform or to modify AI-generated code. It will take me twice the time to analyse the code than to write it new.
My recommendation is that you learn how state-machines work.
You can imagine these states as modes of operation
You have a certain sequence of steps that should run through.
Which means you start with a state 1
- switch-on-glow-plugs and switch on dashboard-control LED change to state 2
- wait predetermined time. If time has passed by turn switch off glow-plugs change to state 3
etc.
here is a tutorial how state-machines work
best regards Stefan