Problemas con delays no obstruyentes usando millis()

Buenass. Estoy intentando realizar un programa para un indoor utilizando un Mega 2560 y retardos no obstruyentes utilizando millis() para cumplir con la lectura constante de pulsaciones botones y de datos de sensores, pero por algún motivo estos "delays" andan descoordinados y a destiempo. Al principio creí que se debía a una desincronización causada por usar Serial.prints, pero me las ingenié para alternar su uso y aún así me sigue surgiendo el mismo problema. Aquí les adjunto el código que tengo por el momento, ya que solo estoy probando lo que hice hasta ahora y la verdad funciona bastante bien:

//Librerias RTC
#include <Wire.h>
#include "RTClib.h"


//Librerias DHT11
#include "DHT.h"


//Librerias DS18B20
#include <OneWire.h>                
#include <DallasTemperature.h>


//Librerias PH-4052C
#include <Arduino.h>


//Librerias LCD
#include <LiquidCrystal.h>


//Librerias Menu
#include <LiquidMenu.h>


//Declaraciones LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


//Declaraciones Sensores y Modulos
RTC_DS3231 rtc;
DateTime date;

DHT dht(22, DHT11); //pin 22

OneWire ourWire(24); //pin24 DS18B20
DallasTemperature sensors(&ourWire);








//Variables pines
int pinBuzzer;  //pin Buzzer (ELEGIR!!)

int conmutador; //pin Conmutador (ELEGIR!!)

int fan; //pin Coolers (ELEGIR!!)

int pHSense = A8; //pin Ph-4052c
int samples = 10; //pin Ph-4052c







//Variables Estado del Hidro-Tech
bool AnimacionInicio = false;  //Determina uso de Animacion de Inicio
bool SerialPrints    = false;  //Determina uso de Serial.prints









//Variables switch
int MuestraLCD = 0;












//Variables Botonera
int boton = A0;
int valor;
















//Variables de Datos y Mediciones
int PlantaSeleccionada    = 100;          //Planta Seleccionada


int CicloDeLuz            = 100;          //Ciclo de Luz Seleccionado
  int Horadecicloluz      = 100;            //Hora de Inicio del Ciclo de Luz


float h = 0;                              //DHT11 Humedad Dentro


float t = 0;                              //DHT11 Temp Dentro
  float TempDentroMax       = 100;          //Temp Dentro Max Seleccionada
  float TempDentroMin       = 100;          //Temp Dentro Min Seleccionada
    float DifTempDentro;


float temp = 0;                           //DS18B20 Temp Agua
  float TempAguaMax         = 100;          //Temp Agua Max Seleccionada
  float TempAguaMin         = 100;          //Temp Agua Min Seleccionada


float adc_resolution = 1024.0;            //Ph-4052c Ph Agua
float voltage;                          
float ph (float voltage) {              
    return 7 + ((2.5 - voltage) / 0.18);
}
  float pHAguaMax           = 100;          //Ph Agua Max Seleccionado
  float pHAguaMin           = 100;          //Ph Agua Min Seleccionado











//Variables del LED
bool EstadoLED      = false;








//Variables de ALERTAS!!
bool AlertaGeneral  = false;

    bool AlertaHum           = false;
    
    bool AlertaTempDentroMax = false;
    bool AlertaTempDentroMin = false;
    
    bool AlertapHAguaMax     = false;
    bool AlertapHAguaMin     = false;
    
    bool AlertaTempAguaMax   = false;
    bool AlertaTempAguaMin   = false;





bool AlertaSeleccionGeneral  = false;

    bool AlertaSeleccionPlanta           = false;

    bool AlertaSeleccionCicloDeLuz       = false;
    bool AlertaSeleccionHoradecicloluz   = false;
    
    
    bool AlertaSeleccionTempDentroMax    = false;
    bool AlertaSeleccionTempDentroMin    = false;
    
    bool AlertaSeleccionpHAguaMax        = false;
    bool AlertaSeleccionpHAguaMin        = false;
    
    bool AlertaSeleccionTempAguaMax      = false;
    bool AlertaSeleccionTempAguaMin      = false;








//Caracteres Nuevos
byte sol[8]        = { B00100, B10001, B01110, B11111, B01110, B10001, B00100, B00000 };
byte luna[8]       = { B00100, B01110, B10111, B00011, B00011, B10111, B01110, B00100 };
byte dospuntos[8]  = { B00000, B00000, B01000, B00000, B00000, B01000, B00000, B00000 };
byte gradoscent[8] = { B11100, B10100, B11100, B00000, B00111, B00100, B00100, B00111 };








//Contadores y Tiempos

unsigned long contadorLecturas = 0;
    int sumadorLecturas = 0;


unsigned long contadorCase1 = 0;
    int sumadorCase1_1 = 0;


unsigned long contadorCase2 = 0;
    int sumadorCase2_1 = 0;
    int sumadorCase2_2 = 0;
    int sumadorCase2_3 = 0;
    int sumadorCase2_4 = 0;
    int sumadorCase2_5 = 0;
    int sumadorCase2_6 = 0;
    int sumadorCase2_7 = 0;
    int sumadorCase2_8 = 0;


unsigned long contadorCase3 = 0;
    int sumadorCase3_1  = 0;
    int sumadorCase3_2  = 0;
    int sumadorCase3_3  = 0;
    int sumadorCase3_4  = 0;
    int sumadorCase3_5  = 0;
    int sumadorCase3_6  = 0;
    int sumadorCase3_7  = 0;
    int sumadorCase3_8  = 0;
    int sumadorCase3_9  = 0;
    int sumadorCase3_10 = 0;
    int sumadorCase3_11 = 0;
    int sumadorCase3_12 = 0;
    int sumadorCase3_13 = 0;
    int sumadorCase3_14 = 0;
    int sumadorCase3_15 = 0;
    int sumadorCase3_16 = 0;
    int sumadorCase3_17 = 0;
    int sumadorCase3_18 = 0;



unsigned long contadorCargando = 0;
    int sumadorCargando1  = 0;
    int sumadorCargando2  = 0;
    int sumadorCargando3  = 0;
    int sumadorCargando4  = 0;
    int sumadorCargando5  = 0;
    



unsigned long contadorGuardando = 0;
    int sumadorGuardando1  = 0;
    int sumadorGuardando2  = 0;
    int sumadorGuardando3  = 0;
    int sumadorGuardando4  = 0;
    int sumadorGuardando5  = 0;
    



int contadorCantAlarmas = 0;


int contadorPrograma = 0;








//Variables del Menu
int  corteMenuUnico    = 0;
int  arranqueMenuUnico = 0;
bool arranqueMenu      = false;
bool programa          = true;











 //------------ Partes del Menu -------------

//------------------Declaración de Lineas-----------------
LiquidLine configuracion  (1, 0, "Configuracion");
LiquidLine salir          (1, 1, "Guardar y Salir");


LiquidLine lechuga  (1, 0, "Lechuga");
LiquidLine tomate   (1, 1, "Tomate");
LiquidLine frutilla (1, 0, "Frutilla");
LiquidLine rucula   (1, 1, "Rucula");


LiquidLine cicloluz   (1, 0, "Ciclo de Luz");

LiquidLine tempdentro (1, 1, "Temp. Dentro");

  LiquidLine tempdentromax (1, 0, "Temp. Maxima");
  
  LiquidLine tempdentromin (1, 1, "Temp. Minima");


LiquidLine phagua     (1, 0, "pH del Agua");

  LiquidLine phaguamax (1, 0, "pH Max");
  
  LiquidLine phaguamin (1, 1, "pH Min");


LiquidLine tempagua   (1, 1, "Temp. del Agua");

  LiquidLine tempaguamax (1, 0, "Temp. Maxima");
  
  LiquidLine tempaguamin (1, 1, "Temp. Minima");



//------------------Declaración de Pantallas-----------------
LiquidScreen InicioMenu;

LiquidScreen Plantas;

LiquidScreen Parametros;

LiquidScreen CiclosdeLuz;
LiquidScreen HoraInicioCiclodeLuz;

LiquidScreen TDentroMaxYMin;
LiquidScreen TDentroMax;
LiquidScreen TDentroMin;

LiquidScreen pHdelAguaMaxYMin;
LiquidScreen pHdelAguaMax;
LiquidScreen pHdelAguaMin;

LiquidScreen TAguaMaxYMin;
LiquidScreen TAguaMax;
LiquidScreen TAguaMin;


//------------------Declaración de Menu-----------------
LiquidMenu menu(lcd);











void setup() {
   Serial.begin(9600);

   lcd.begin(16,2);
   
   sensors.begin();

   dht.begin();
    
   // Asigna los nuevos caracteres por numeros
   lcd.createChar(1, sol);      
   lcd.createChar(2, luna);
   lcd.createChar(3, dospuntos);
   lcd.createChar(4, gradoscent);
   
     
   pinMode(pinBuzzer,  OUTPUT);
   pinMode(conmutador, OUTPUT);
   pinMode(fan,        OUTPUT);
  
  
   //-------------------------- Add Lines ----------------------------
   InicioMenu.add_line(configuracion);
   InicioMenu.add_line(salir);
  
   Plantas.add_line(lechuga);
   Plantas.add_line(tomate);
   Plantas.add_line(frutilla);
   Plantas.add_line(rucula);
  
   Parametros.add_line(cicloluz);
   Parametros.add_line(tempdentro);
   Parametros.add_line(phagua);
   Parametros.add_line(tempagua);
  
   TDentroMaxYMin.add_line(tempdentromax);
   TDentroMaxYMin.add_line(tempdentromin);
  
   pHdelAguaMaxYMin.add_line(phaguamax);
   pHdelAguaMaxYMin.add_line(phaguamin);
  
   TAguaMaxYMin.add_line(tempaguamax);
   TAguaMaxYMin.add_line(tempaguamin);
  
  
  
   //------------------ Set Focus Position ---------------------
   configuracion.set_focusPosition(Position::LEFT);
   salir.set_focusPosition(Position::LEFT);
  
   lechuga.set_focusPosition(Position::LEFT);
   tomate.set_focusPosition(Position::LEFT);
   frutilla.set_focusPosition(Position::LEFT);
   rucula.set_focusPosition(Position::LEFT);
  
   cicloluz.set_focusPosition(Position::LEFT);
   tempdentro.set_focusPosition(Position::LEFT);
   phagua.set_focusPosition(Position::LEFT);
   tempagua.set_focusPosition(Position::LEFT);
  
   tempdentromax.set_focusPosition(Position::LEFT);
   tempdentromin.set_focusPosition(Position::LEFT);
  
   phaguamax.set_focusPosition(Position::LEFT);
   phaguamin.set_focusPosition(Position::LEFT);
  
   tempaguamax.set_focusPosition(Position::LEFT);
   tempaguamin.set_focusPosition(Position::LEFT);
  
  
  
  
   //------------------ Attach Functions ---------------------
   configuracion.attach_function(1, fn_config);
   salir.attach_function(1, fn_salir);
  
   lechuga.attach_function(1, fn_lechuga);
   tomate.attach_function(1, fn_tomate);
   frutilla.attach_function(1, fn_frutilla);
   rucula.attach_function(1, fn_rucula);
  
   cicloluz.attach_function(1, fn_cicloluz);
   tempdentro.attach_function(1, fn_tempdentro);
   phagua.attach_function(1, fn_phagua);
   tempagua.attach_function(1, fn_tempagua);
  
   tempdentromax.attach_function(1, fn_tempdentromax);
   tempdentromin.attach_function(1, fn_tempdentromin);
 
   phaguamax.attach_function(1, fn_phaguamax);
   phaguamin.attach_function(1, fn_phaguamin);
    
   tempaguamax.attach_function(1, fn_tempaguamax);
   tempaguamin.attach_function(1, fn_tempaguamin);
  
  
   //-------------------- Add Screens -------------------
   menu.add_screen(InicioMenu);             //Pantalla  1
  
   menu.add_screen(Plantas);                //Pantalla  2
  
   menu.add_screen(Parametros);             //Pantalla  3
    
   menu.add_screen(TDentroMaxYMin);         //Pantalla 4
  
   menu.add_screen(pHdelAguaMaxYMin);       //Pantalla 5
  
   menu.add_screen(TAguaMaxYMin);           //Pantalla 6
  
  
  
  
   InicioMenu.set_displayLineCount(2);
  
   Plantas.set_displayLineCount(2);
  
   Parametros.set_displayLineCount(2);
  
   TDentroMaxYMin.set_displayLineCount(2);
  
   pHdelAguaMaxYMin.set_displayLineCount(2);
  
   TAguaMaxYMin.set_displayLineCount(2);
  
  
   menu.set_focusedLine(0);
  
   menu.update();

   Hide();






  // Animacion de Inicio

  if (AnimacionInicio == true){
    
    lcd.clear();
    delay(250);
    
    lcd.setCursor(3, 0);
    lcd.print("H");
    Serial.println("HIDRO-TECH");
    delay(100);
    
    lcd.setCursor(3, 0);
    lcd.print("HI");
    Serial.println("Bienvenido!!");
    Serial.println(" ");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HID");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDR");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-T");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TE");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TEC");
    delay(100);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TECH");
    delay(500);
  
    lcd.clear();
    delay(150);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TECH");
    delay(500);
  
    lcd.clear();
    delay(150);
  
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TECH");
    delay(1000);
  
    
    
    lcd.setCursor(2, 1);
    lcd.print("Bienvenido!!");
    delay(1000);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("HIDRO-TECH");
    lcd.setCursor(2, 1);
    lcd.print(" ienvenido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print(" IDRO-TECH");
    lcd.setCursor(2, 1);
    lcd.print("  envenido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("  DRO-TECH");
    lcd.setCursor(2, 1);
    lcd.print("   nvenido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("   RO-TECH");
    lcd.setCursor(2, 1);
    lcd.print("    venido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("    O-TECH");
    lcd.setCursor(2, 1);
    lcd.print("     enido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("     -TECH");
    lcd.setCursor(2, 1);
    lcd.print("      nido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("      TECH");
    lcd.setCursor(2, 1);
    lcd.print("       ido!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("       ECH");
    lcd.setCursor(2, 1);
    lcd.print("        do!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("        CH");
    lcd.setCursor(2, 1);
    lcd.print("         o!!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("         H");
    lcd.setCursor(2, 1);
    lcd.print("          !!");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print(" ");
    lcd.setCursor(2, 1);
    lcd.print("           !");
    delay(150);
  
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print(" ");
    lcd.setCursor(2, 1);
    lcd.print(" ");
    delay(200);
  
    lcd.setCursor(2, 0);
    lcd.print("Iniciando");
    Serial.println("Iniciando...");
    Serial.println(" ");
    delay(200);
  
    lcd.setCursor(2, 0);
    lcd.print("Iniciando.");
    delay(500);
    
    lcd.setCursor(2, 0);
    lcd.print("Iniciando..");
    delay(500);
  
    lcd.setCursor(2, 0);
    lcd.print("Iniciando...");
    delay(500);
  
    lcd.clear();
    delay(150);
    
    lcd.setCursor(2, 0);
    lcd.print("Iniciado!");
    delay(350);
  
    Serial.println("Programa Iniciado!!");
    Serial.println(" ");
    Serial.println(" ");
    Serial.println(" ");
  
    lcd.clear();
    delay(150);
    
  }


} //Fin de setup





















void loop() {


    if (millis() > contadorLecturas && sumadorLecturas == 0){
      
      // ------------------------ Lectura de Botones -------------------------
    
      valor = analogRead(boton);
  
      if (valor > 600 && valor < 650 && arranqueMenu == false) { // ARRANQUE DEL MENU
                                        // El SELECT se utiliza para arrancarlo, como si fuese un BOTON MENU
          arranqueMenu = true;

          if (SerialPrints == true){
            Serial.println("ARRANQUE MENU");
            Serial.println(" ");
          }
          
      }
    
      if (valor > 250 && valor < 260 && arranqueMenu == true){ //ABAJO
          menu.switch_focus(true);
      }
        
      if (valor > 90 && valor < 150 && arranqueMenu == true){  //ARRIBA
          menu.switch_focus(false);
      }
  
      if (valor > 400 && valor < 410 && arranqueMenu == true){ //ATRAS
          menu.change_screen(1);
          menu.set_focusedLine(0);
      }
  
      if(valor > -20 && valor < 50 && arranqueMenu == true){   //SELECCIONAR
        menu.call_function(1);
      }
  
  


  
       // ------------------------- Mediciones de Parametros ------------------------
  
       h = dht.readHumidity(); //Medicion Humedad
    
     
       t = dht.readTemperature(); //Medicion Temperatura Interior
    
    
       sensors.requestTemperatures(); 
       temp = sensors.getTempCByIndex(0); //Medicion Temperatura Agua
    
       
       int measurings = 0;
       for (int i = 0; i < samples; i++){
         measurings += analogRead(pHSense);
       }
       voltage = 5 / adc_resolution * measurings/samples; //Medicion pH Agua




      



    // --------------- Verificación de Seleccion de Datos en Menu ------------------

     if (PlantaSeleccionada == 100){ //Activacion ALERTA SELECCION DE PLANTA!!
      AlertaSeleccionPlanta = true;
      AlertaSeleccionGeneral  = true;
     }



     if (CicloDeLuz == 100){ //Activacion ALERTA SELECCION DE CICLO DE LUZ!!
      AlertaSeleccionCicloDeLuz = true;
      AlertaSeleccionGeneral  = true;
     }

         if (Horadecicloluz == 100){ //Activacion ALERTA SELECCION DE HORA DE INICIO DE CICLO DE LUZ!!
          AlertaSeleccionHoradecicloluz = true;
          AlertaSeleccionGeneral  = true;
         }



     if (TempDentroMax == 100){ //Activacion ALERTA SELECCION DE TEMP DENTRO MAX!!
      AlertaSeleccionTempDentroMax = true;
      AlertaSeleccionGeneral  = true;
     }

     if (TempDentroMin == 100){ //Activacion ALERTA SELECCION DE TEMP DENTRO MIN!!
      AlertaSeleccionTempDentroMin = true;
      AlertaSeleccionGeneral  = true;
     }



     if (TempAguaMax == 100){ //Activacion ALERTA SELECCION DE TEMP DE AGUA MAX!!
      AlertaSeleccionTempAguaMax = true;
      AlertaSeleccionGeneral  = true;
     }

     if (TempAguaMin == 100){ //Activacion ALERTA SELECCION DE TEMP DE AGUA MIN!!
      AlertaSeleccionTempAguaMin = true;
      AlertaSeleccionGeneral  = true;
     }



     if (pHAguaMax == 100){ //Activacion ALERTA SELECCION DE PH DE AGUA MAX!!
      AlertaSeleccionpHAguaMax = true;
      AlertaSeleccionGeneral  = true;
     }

     if (pHAguaMin == 100){ //Activacion ALERTA SELECCION DE PH DE AGUA MIN!!
      AlertaSeleccionpHAguaMin = true;
      AlertaSeleccionGeneral  = true;
     }


     



     
     // ------------------------ Verificación de ALERTAS!! ------------------------

     if (h > 85){ //Personalizar Humedad Dentro Max
      AlertaHum = true;
      AlertaGeneral = true;
     }
     
     if (t > TempDentroMax && TempDentroMax != 100){
      AlertaTempDentroMax = true;
      AlertaGeneral = true;
     }

     if (t < TempDentroMin && TempDentroMin != 100){
      AlertaTempDentroMin = true;
      AlertaGeneral = true;
     }

     if (temp > TempAguaMax && TempAguaMax != 100){
      AlertaTempAguaMax = true;
      AlertaGeneral = true;
     }

     if (temp < TempAguaMin && TempAguaMin != 100){
      AlertaTempAguaMin = true;
      AlertaGeneral = true;
     }

     if (ph(voltage) > pHAguaMax && pHAguaMax != 100){
      AlertapHAguaMax = true;
      AlertaGeneral = true;
     }

     if (ph(voltage) < pHAguaMin && pHAguaMin != 100){
      AlertapHAguaMin = true;
      AlertaGeneral = true;
     }





      // --------------------- Verificacion de que NO hay ALERTAS!! ----------------

      if (AlertaSeleccionGeneral == false && AlertaGeneral == false && arranqueMenu == false){
        programa = true;
      }






      // ------------------- Verificacion de case 1 (MuestraLCD) -----------------

      if (programa == true){
        MuestraLCD = 1;
      }







       sumadorLecturas = 1;

       if (SerialPrints == true){
         Serial.print("Lecturas Realizadas (Datos de Parametros y Botonera)!!  - ");
         Serial.print(millis());
         Serial.print(" ms");
         Serial.println(" ");
         Serial.println(" ");
         Serial.println(" ");     
       }
       



    }


    if (millis() > contadorLecturas + 100){

      
      contadorLecturas = millis();

      sumadorLecturas = 0;
    }

      // ---------------------- Verificación Inicio de Menu -----------------

      if (arranqueMenu == true) {
        
        programa = false;
        
        arranqueMenuUnico = 1;

        MuestraLCD = 3;
      }









    
//----------------------------- Regulación Coolers ----------------------------------

    DifTempDentro = TempDentroMax - TempDentroMin; // Toma la diferencia entre TempDentroMax y TempDentroMin
                                                   // para realizar las distintas velocidades de los coolers.
    if (t <= TempDentroMin) {
      analogWrite(fan, 50);
    }

    if (t > TempDentroMin && t <= TempDentroMin + (DifTempDentro / 4)) {
      analogWrite(fan, 100);
    }

    if (t > TempDentroMin + (DifTempDentro / 4) && t <= TempDentroMin + 2*(DifTempDentro / 4)) {
      analogWrite(fan, 150);
    }

    if (t > TempDentroMin + 2*(DifTempDentro / 4) && t <= TempDentroMin + 3*(DifTempDentro / 4)) {
      analogWrite(fan, 200);
    }

    if (t >  TempDentroMin + 3*(DifTempDentro / 4)&& t <= TempDentroMax) {
      analogWrite(fan, 250);
    }

    if (t >= TempDentroMax) {
      analogWrite(fan, 255);
    }




switch (MuestraLCD){
  
  case 1: // Muestra de Datos

    if (millis() > contadorCase1 && sumadorCase1_1 == 0){
      
        Hide();
        
        lcd.clear();

        // ----------------------------------- Muestras de Temperatura Ambiente -----------------------

        lcd.setCursor(0, 0);
        lcd.print("T ");
        lcd.setCursor(2, 0);
        lcd.write(byte(3));
        lcd.setCursor(3, 0);
        lcd.print(t);
        
        lcd.setCursor(7, 0);
        lcd.write(byte(4));
    

        // ----------------------------------- Muestras de Humedad Ambiente ---------------------------

        lcd.setCursor(9, 0);
        lcd.print("H ");
        lcd.setCursor(11, 0);
        lcd.write(byte(3));
        lcd.setCursor(12, 0);
        lcd.print(h);
        
        lcd.setCursor(15, 0);
        lcd.print("%");


        // ----------------------------------- Muestras de Temperatura Agua ---------------------------

        lcd.setCursor(0, 1);
        lcd.print("Ta");
        lcd.setCursor(2, 1);
        lcd.write(byte(3));
        lcd.setCursor(3, 1);
        lcd.print(temp);
        
        lcd.setCursor(7, 1);
        lcd.write(byte(4));


        // ----------------------------------- Muestras de pH Agua ------------------------------------

        lcd.setCursor(9, 1);
        lcd.print("pH ");
        lcd.setCursor(11, 1);
        lcd.write(byte(3));
        lcd.setCursor(12, 1);
        lcd.print(ph(voltage));


        lcd.setCursor(8, 0);
        lcd.print (" ");

        lcd.setCursor(8, 1);
        lcd.print (" ");




        if (SerialPrints == true){
          Serial.print("Temperatura del Interior: ");
          Serial.print(t);
          Serial.println("°C");
          Serial.println(" ");

          Serial.print("Humedad del Interior: ");
          Serial.print(h);
          Serial.println("%");
          Serial.println(" ");
          
          Serial.print("Temperatura del Agua: ");
          Serial.print(temp);
          Serial.println("°C");
          Serial.println(" ");
          
          Serial.print("Nivel de pH: ");
          Serial.println(ph(voltage));
          Serial.println(" ");

          Serial.println(" ");
          Serial.println(" ");
          Serial.println(" ");
        }

        
        sumadorCase1_1 = 1;
    }


    if (millis() > contadorCase1 + 3000){
        contadorCase1 = millis();
        
        sumadorCase1_1 = 0;
    }


    
  break; //Fin case 1











  case 2: // Muestra de Datos y ALERTAS!!

    Hide();

    if (millis() > contadorCase2 && sumadorCase2_1 == 0){
      
        lcd.clear();

        // ----------------------------------- Muestras de Temperatura Ambiente -----------------------

        lcd.setCursor(0, 0);
        lcd.print("T ");
        lcd.setCursor(2, 0);
        lcd.write(byte(3));
        lcd.setCursor(3, 0);
        lcd.print(t);
        
        lcd.setCursor(7, 0);
        lcd.write(byte(4));


        // ----------------------------------- Muestras de Humedad Ambiente ---------------------------

        lcd.setCursor(9, 0);
        lcd.print("H ");
        lcd.setCursor(11, 0);
        lcd.write(byte(3));
        lcd.setCursor(12, 0);
        lcd.print(h);
        
        lcd.setCursor(15, 0);
        lcd.print("%");
        


        // ----------------------------------- Muestras de Temperatura Agua ---------------------------

        lcd.setCursor(0, 1);
        lcd.print("Ta");
        lcd.setCursor(2, 1);
        lcd.write(byte(3));
        lcd.setCursor(3, 1);
        lcd.print(temp);
        
        lcd.setCursor(7, 1);
        lcd.write(byte(4));



        // ----------------------------------- Muestras de pH Agua ------------------------------------
        

        lcd.setCursor(9, 1);
        lcd.print("pH ");
        lcd.setCursor(11, 1);
        lcd.write(byte(3));
        lcd.setCursor(12, 1);
        lcd.print(ph(voltage));



        lcd.setCursor(8, 0);
        lcd.print (" ");

        lcd.setCursor(8, 1);
        lcd.print (" ");




        if (SerialPrints == true){
          Serial.print("Temperatura del Interior: ");
          Serial.print(t);
          Serial.println("°C");
          Serial.println(" ");

          Serial.print("Humedad del Interior: ");
          Serial.print(h);
          Serial.println("%");
          Serial.println(" ");
          
          Serial.print("Temperatura del Agua: ");
          Serial.print(temp);
          Serial.println("°C");
          Serial.println(" ");
          
          Serial.print("Nivel de pH: ");
          Serial.println(ph(voltage));
          Serial.println(" ");

          Serial.println(" ");
          Serial.println(" ");
          Serial.println(" ");
        }


        
        sumadorCase2_1 = 1;
    }


        
    if(AlertaHum == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;
      
        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_2 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("HUMEDAD ALTA!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Humedad Interior MUY ALTA!!");
            Serial.print(h);
            Serial.println("%!!");
          }

          sumadorCase2_2 = 1;
        }
        
    }



    if(AlertaTempDentroMax == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_3 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("TEMP INT ALTA!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Temperatura Interior MUY ALTA!!");
            Serial.print(t);
            Serial.println("°C!!");
          }

          sumadorCase2_3 = 1;
        }
        
    }



    if(AlertaTempDentroMin == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_4 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("TEMP INT BAJA!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Temperatura Interior MUY BAJA!!");
            Serial.print(t);
            Serial.println("°C!!");
          }

          sumadorCase2_4 = 1;
        }
    }



    if(AlertapHAguaMax == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_5 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("pH AGUA ALTO!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Nivel de pH del Agua MUY ALTO!!");
            Serial.print(ph(voltage));
            Serial.println("!!");
          }

          sumadorCase2_5 = 1;
        }
    }



    if(AlertapHAguaMin == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_6 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("pH AGUA BAJO!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Nivel de pH del Agua MUY BAJO!!");
            Serial.print(ph(voltage));
            Serial.println("!!");
          }

          sumadorCase2_6 = 1;
        }
    }



    if(AlertaTempAguaMax == true){
      
      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_7 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("TEMP AGUA ALTA!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Temperatura del Agua MUY ALTA!!");
            Serial.print(temp);
            Serial.println("°C!!");
          }

          sumadorCase2_7 = 1;
        }
    }



    if(AlertaTempAguaMin == true){

      contadorCantAlarmas = contadorCantAlarmas + 1;

        if (millis() > contadorCase2 + contadorCantAlarmas * 1000 && sumadorCase2_8 == 0){
          lcd.clear();
          
          lcd.setCursor(5, 0);
          lcd.print("ALERTA!!");
          lcd.setCursor(1, 1);
          lcd.print("TEMP AGUA BAJA!!");

          if (SerialPrints == true){
            Serial.println("ALERTA!! Temperatura del Agua MUY BAJA!!");
            Serial.print(temp);
            Serial.println("°C!!");
          }

          sumadorCase2_8 = 1;
        }
    }
    
    if (millis() > contadorCase2 + contadorCantAlarmas * 1000){
        contadorCase2 = millis();

        contadorCantAlarmas = 0;
        
        sumadorCase2_1 = 0;
        sumadorCase2_2 = 0;
        sumadorCase2_3 = 0;
        sumadorCase2_4 = 0;
        sumadorCase2_5 = 0;
        sumadorCase2_6 = 0;
        sumadorCase2_7 = 0;
        sumadorCase2_8 = 0;
    }



    
  break; //Fin case 2











  case 3: // Menu

    if (arranqueMenuUnico == 1) {
      

      //--------------- SECUENCIA INICIO MENU ------------------
      
      if (millis() > contadorCase3 && sumadorCase3_1 == 0){
  
        contadorCase3 = millis();

        if (SerialPrints == true){
          Serial.println("Iniciando Menu...");
          Serial.println(" ");
        }
  
        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("MENU DE");
        lcd.setCursor(1, 1);
        lcd.print("CONFIGURACION");
  
        sumadorCase3_1 = 1;
      }
  
  
      if (millis() > contadorCase3 + 2000 && sumadorCase3_2 == 0){
  
        lcd.clear();
  
        arranqueMenuUnico = 2;
        
        contadorCase3 = millis();

        
        menu.change_screen(1);
        menu.set_focusedLine(0);

        if (SerialPrints == true){
          Serial.println("Inicio del Menu!");
          Serial.println("");
          Serial.println("");
          Serial.println("");
        }
  
        sumadorCase3_2 = 1;
          
      }
  }



  break; //Fin case 3







  case 4: //Secuencia de Cargando

    if (millis() > contadorCargando && sumadorCargando1 == 0){
  
        contadorCargando = millis();

        if (SerialPrints == true){
          Serial.println("Cargando...");
          Serial.println(" ");
        }
  
        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Cargando");
  
        sumadorCargando1 = 1;
      }



      if (millis() > contadorCargando + 500 && sumadorCargando2 == 0){

        lcd.setCursor(2, 0);
        lcd.print("Cargando.");
  
        sumadorCargando2 = 1;
      }



      if (millis() > contadorCargando + 1000 && sumadorCargando3 == 0){
  
        lcd.setCursor(2, 0);
        lcd.print("Cargando..");
  
        sumadorCargando3 = 1;
      }



      if (millis() > contadorCargando + 1500 && sumadorCargando4 == 0){
        
        lcd.setCursor(2, 0);
        lcd.print("Cargando...");
  
        sumadorCargando4 = 1;
      }



      if (millis() > contadorCargando + 2000){

        sumadorCargando1 = 0;
        sumadorCargando2 = 0;
        sumadorCargando3 = 0;
        sumadorCargando4 = 0;
        sumadorCargando5 = 0;
        
        fn_config();
        
      }

  break; //Fin case 4


  



  case 5: //Secuencia de Guardando

    if (millis() > contadorGuardando && sumadorGuardando1 == 0){
  
        contadorGuardando = millis();

        if (SerialPrints == true){
          Serial.println("Guardando...");
          Serial.println(" ");
        }
  
        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Guardando");
  
        sumadorGuardando1 = 1;
      }



      if (millis() > contadorGuardando + 500 && sumadorGuardando2 == 0){

        lcd.setCursor(2, 0);
        lcd.print("Guardando.");
  
        sumadorGuardando2 = 1;
      }



      if (millis() > contadorGuardando + 1000 && sumadorGuardando3 == 0){
  
        lcd.setCursor(2, 0);
        lcd.print("Guardando..");
  
        sumadorGuardando3 = 1;
      }



      if (millis() > contadorGuardando + 1500 && sumadorGuardando4 == 0){
        
        lcd.setCursor(2, 0);
        lcd.print("Guardando...");
  
        sumadorGuardando4 = 1;
      }



      if (millis() > contadorGuardando + 2250 && sumadorGuardando5 == 0){

        if (SerialPrints == true){
          Serial.println("Guardado!!");
          Serial.println(" ");
          Serial.println(" ");
          Serial.println(" ");
        }

        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Guardado!!");
  
        sumadorGuardando5 = 1;
      }



      if (millis() > contadorGuardando + 2500){
        
        lcd.clear();

        programa = true;


        sumadorGuardando1 = 0;
        sumadorGuardando2 = 0;
        sumadorGuardando3 = 0;
        sumadorGuardando4 = 0;
        sumadorGuardando5 = 0;
      }

  break; //Fin case 5







} //Fin switch (MuestraLCD)




} //Fin void loop

















void Hide(){
  LiquidScreen hide(LiquidScreen);
  lcd.clear();
}




















//------------------------- Funciones del Menu --------------------

void fn_config(){

  menu.change_screen(2);
  menu.set_focusedLine(0);
  
}

void fn_salir(){

  arranqueMenu      = false;
  arranqueMenuUnico = 0;

  MuestraLCD = 5;

  LiquidScreen hide(LiquidScreen);
  lcd.clear();

      sumadorCase3_1  = 0;
      sumadorCase3_2  = 0;
  
}




void fn_lechuga() {
  menu.change_screen(3);
  menu.set_focusedLine(0);
  PlantaSeleccionada = 1;
}





void fn_tomate() {
  menu.change_screen(3);
  menu.set_focusedLine(0);
  PlantaSeleccionada = 2;
}





void fn_frutilla() {
  menu.change_screen(3);
  menu.set_focusedLine(0);
  PlantaSeleccionada = 3;
}





void fn_rucula() {
  menu.change_screen(3);
  menu.set_focusedLine(0);
  PlantaSeleccionada = 4;
}




void fn_cicloluz(){
  
}



void fn_tempdentro() {
  menu.change_screen(6);
  menu.set_focusedLine(0);
}

    void fn_tempdentromax(){
      
    }
    
    void fn_tempdentromin(){
      
    }

void fn_phagua() {
  menu.change_screen(9);
  menu.set_focusedLine(0);
}

    void fn_phaguamax(){
      
    }
    
    void fn_phaguamin(){
      
    }

void fn_tempagua() {
  menu.change_screen(12);
  menu.set_focusedLine(0);
}

    void fn_tempaguamax(){
      
    }
    
    void fn_tempaguamin(){
      
    }

Para guiarlos un poco, este consta con una etapa de muestras de datos y alertas mediante un LCD 16x2, y otra etapa en la que se desarrolla un menu utilizando el mismo LCD y una botonera. Repito, aun no está terminado, solo ando probando lo que tengo hecho...

Espero puedan ayudarme. Si poseen un Arduino y un LCD 16x2 podrán probarlo.
Gracias

No hacen falta, existen Proteus y Wokwi.com :wink:

Imagino que el artefacto va a trabajar 24/7 entonces

millis() > contadorCase1 + 3000)

debes cambiarlo por

millis() - contadorCase1 >= 3000)

o de manera general

millis() - tiempo_anterior >= intervalo

ya que es la forma correcta de hacerlo para evitar problemas con el reinicio de millis() cada 49 días y medio.

Asi es. La idea es que funcione 24/7.

Probé cambiando como me dijiste de esta forma

millis() - contadorCase1 >= intervalo

y sigo teniendo el mismo problema.

El loop tarda alrededor de 750ms en repetirse y eso me trae problemas a la hora de leer el estado de los botones.

¿Que es lo que me provoca que tarde tanto?

Los 750 mseg de demora son culpa del sensor de temperatura, es lo que demora la lectura.
Una posible solución

o buscar una librería alternativa a DallasTemperature que sea "no bloqueante" como NonBlockingDallas.

Es cierto, ese era el problema. Busque una libreria de NonBlockingDallas y me funciona a la perfección. Muchisimas gracias!!

[GitHub - gfvalvo/nonBlockingDS18B20: Convenience Wrapper for Dallas Temperature Library] para quienes estén interesados en usar dicha libreria.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.