Code for cranking engine

Good day guys,

Project overview - I am building a generator control board to start and stop the engine.
Going to install a speed sensor on flywheel to determine engine RPM.

I have googled but can only find examples using a standard delay function.

But I do not want to use a standard time for cranking the engine as the time that the engine could take to start differs due to environmental factors - cold etc.

What I want to do is for the starter to keep on cranking until the engine reaches a certain speed - (speed threshold is to indicate that the engine has started), in the event of a no start condition there must be a time out for the starter.

So engine cranks until certain speed is reached (starter kicks out) or if engine doesn't start starter kicks out after say 30 sec.

Does any one have some suggestions on how the code will look like for above?

Thanks in advance

Does any one have some suggestions on how the code will look like for above?

Something like this pseudo code perhaps

start time = millis()
while (rpm < threshold and current time - start time <= 30 seconds)
{
  current time = millis()
  //code here to measure rpm
  crank the engine
}

Thanks for pointing me in the correct direction UKHeliBob, I am going to try this.

Thanks again
keep well!

Note that as written the while loop will stop the program doing anything else until it exits