Gestione cicli. Quale usare?

Buongiorno,
ho la necessità di creare una serie di cicli e condizioni come l'allegato in foto.
Consigli?

Difficile fuori contesto. Il ciclo esterno nel disegno è un while()
ma la loop() è già un ciclo while() perchè viene chiamato di continuo, quindi basterebbe una if

L'idea è quella di visualizzare da subito la temperatura fino a quando non viene premuto un tasto.
Nel caso venga premuto un tasto si attiva un menù fino a quando non si preme il pulsante ESC alla ROOT del menù (e non so come implementarlo) e, per un tempo massimo di circa 5 minuti.
Allego la bozza del progetto. La parte del menù è però da ripulire in quanto ci sono ancora parte delle voci dell'esempio dal quale è stato estrapolato.

ArduAcquario_MALAWI_OLED.ino (11.3 KB)

LCDML_CONTROL.ino (4.05 KB)

LCDML_DISP.ino (3.65 KB)

LCDML_FUNC_BACKEND.ino (1.12 KB)

LCDML_FUNC_DISP.ino (7.62 KB)

nid69ita:
Difficile fuori contesto. Il ciclo esterno nel disegno è un while()
ma la loop() è già un ciclo while() perchè viene chiamato di continuo, quindi basterebbe una if

Ho provato in questo modo ma non riesco a restare nel menù per il empo desiderato. Se premo un pulsante il menù viene visualizzato solo per pochissimi secondi e, se inserisco un Serial.print per verificare se entra nel ciclio else if (millicorrenti - milliprecedenti > intervallo) mi accorgo che ciò non avviene.

Questo è un'estratto del codice:

long milliprecedenti = 0;
long intervallo = 30000; 
void setup()
{

  //set up LEDs
  pinMode (led_red, OUTPUT);
  digitalWrite(led_red, LOW);
  pinMode (led_green, OUTPUT);
  digitalWrite(led_green, LOW);

  u8g2.begin();
  Serial.begin(115200);                // start serial
  Serial.println("");
  Serial.print("ArduAcquario MALAWI ");
  Serial.println (Version);
  Serial.print("By Ettore Di Fabio ");
  Serial.println (date_Version);
  Serial.print (F("VERSIONE LCD: ")); // only for examples
  Serial.println(F(_LCDML_VERSION)); // only for examples

  // Enable all items with _LCDML_G1
  LCDML_DISP_groupEnable(_LCDML_G1); // enable group 1

  // LCDMenu Setup
  LCDML_setup(_LCDML_BACK_cnt);

  delay(1000);
}

void Temp() //Funzione che visualizza la temperatura
{
  u8g2.setFont(_LCDML_DISP_font);
  u8g2.firstPage();

  // Send the command to get temperatures.
  sensors.requestTemperatures();

  // Read temperature of Dallas sensor
  tempDALLAS = sensors.getTempCByIndex(0);

  // Show the temerature o the OLED Display
  u8g2.drawStr( 5, 10, "ArduAcquario MALAWI");
  u8g2.drawStr( 0, 25, "Temperatura Acquario");
  u8g2.setCursor( 40, 40);
  u8g2.print(tempDALLAS);
  u8g2.drawStr (70, 40, "\260 C");
  u8g2.drawStr( 10, 62, "any button to menu'");
  digitalWrite(led_green, HIGH); //Turn ON Green Led
  digitalWrite (led_red, LOW); //Turn OFF Red Led
  Serial.println();
  Serial.print("Temperatura acqua OK ");
  Serial.println(tempDALLAS);
}



// *********************************************************************
// LOOP
// *********************************************************************
void loop()
{
  sensors.requestTemperatures();
  tempDALLAS = sensors.getTempCByIndex(0);   // Read temperature of Dallas sensor
  unsigned long millicorrenti = millis();

    u8g2.firstPage();
  do {
      if  (!LCDML_BUTTON_checkAny())
  { // check if any button is presed (enter, up, down, left, right)
     Temp();
     Serial.println(millicorrenti - milliprecedenti);
  }
  else if (millicorrenti - milliprecedenti > intervallo)
  {
    milliprecedenti = millicorrenti;

    u8g2.firstPage();// this function must called here, do not delete it
    LCDML_run(_LCDML_priority);
    Serial.println("PULSANTE PREMUTO");
    // LCDML_DISP_funcend calls the loop_end function
    LCDML_DISP_funcend();
  }
    }
  while ( u8g2.nextPage() );

  // Check the temperature
  while (tempDALLAS <= 25)
  {
    u8g2.firstPage();
    do {
      sensors.requestTemperatures();
      tempDALLAS = sensors.getTempCByIndex(0);   // Read temperature of Dallas sensor
      digitalWrite (led_green, LOW ); //set the LED off
      digitalWrite (led_red, HIGH); //set the LED on
      Serial.println();
      Serial.print("Temperatura acqua troppo BASSA! ");
      Serial.println(tempDALLAS);

      u8g2.drawStr( 5, 10, "ArduAcquario MALAWI");
      u8g2.drawStr( 30, 25, "ALLERT!");
      u8g2.drawStr( 0, 38, "Temperatura Acquario");
      u8g2.drawStr( 20, 51, "TROPPO BASSA!");
      u8g2.setCursor( 40, 63);
      u8g2.print(tempDALLAS);
      delay(500);
    } while ( u8g2.nextPage() );
  }


  while (tempDALLAS >= 29)
  {
    u8g2.firstPage();
    do {
      sensors.requestTemperatures();
      tempDALLAS = sensors.getTempCByIndex(0);   // Read temperature of Dallas sensor
      digitalWrite (led_green, LOW ); //set the LED off
      digitalWrite (led_red, HIGH); //set the LED on
      Serial.println();
      Serial.print("Temperatura acqua troppo ALTA! ");
      Serial.println(tempDALLAS);

      u8g2.drawStr( 5, 10, "ArduAcquario MALAWI");
      u8g2.drawStr( 30, 25, "ALLERT!");
      u8g2.drawStr( 0, 38, "Temperatura Acquario");
      u8g2.drawStr( 20, 51, "TROPPO ALTA!");
      u8g2.setCursor( 40, 63);
      u8g2.print(tempDALLAS);
      delay(500);
    } while ( u8g2.nextPage() );
  }

  // this function must called here, do not delete it
  LCDML_run(_LCDML_priority);
}