Issue with exiting menu

Hi there!

first Post around here, hope you guys can help me out with this little issue....

So I've created a little system for controlling my ventilator and I've setup various Menu's for this (Always-on-mode, off-mode, ECO-mode etc.)

In the Menus itself is a while loop which runs a couple of things and checks whether a certain button is pushed or not. As soon as I push this button the mode exits and returns to the "main" menu where I can select on of the other menus.

Now as these loops are fairly quick (max 2 secs) I only have to keep the button pushed for max 2 seconds for the menu to quit. Except for the ECO mode...

In this one I would like the ventilator to run for 1 minute and then pause for 5. Which means that 6 minutes pass until the "is-the-button-pushed" condition is checked again. So in order to get back to the other menus I would have to, in the worst case, keep the button pushed for 6 minutes... You get the impracticality of that...

I tried implementing a for loop that checks if the button is pushed within the while-loop but it did not really work....

Any ideas what could be the best solution here?

Thanks a lot and stay safe!

Pete

No code posted = no help possible

Read this before posting a programming question

Right, my bad.

Here is the code within the ECO-mode menu:

void ECO(){
  
  delay(500);
  while(digitalRead(select) == 1)
  {
    lcd.clear();
    int chk = DHT.read11(DHT11_PIN);
    lcd.setCursor(0,0);
    lcd.print("Temp: "+(String)DHT.temperature+(char)223+"C");
    lcd.setCursor(0,1);
    lcd.print("Humidity: "+(String)DHT.humidity+"%");
    digitalWrite(8, HIGH); //turning ventilator on
    delay(5000);
    digitalWrite(8, LOW); //tunrning ventilator off
    delay(5000);
    continue;  
  }
}

As you did not post a complete sketch (why not ?) it is difficult to see the problem in context but in general you would be better using millis() for timing in a state machine.

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE for advice on using millis() and Google for advice on state machines