Correton:
El problema esta en el uso de delay(), hay que cambiarlo por millis().
Acá te paso como me parece que debería ser el código.
Lo hice de ojo porque no tengo la libraría, si no compila por ahí es por algún error menor (jeje).
También cambie “char key = keypad.getKey();” porque no veo sentido en que siga si no se entro ninguna tecla.
Revisalo y contame.
Saludos.
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
long timepofinaldisplay = 0;
int cursorcol;
int tecla;
int mediciontemperatura;
int prueba;
float temp;
const byte filas = 4; //cuatro filas
const byte columnas = 3; //tres columnas
char keys[filas][columnas] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte pinsfilas[filas] = {10, 9, 8, 7}; //PINS ENTRADAS FILAS EN ORDEN F1 F2 F3 F4
byte pinscolumnas[columnas] = {6, 14, 15}; //PINS ENTRADA COLUMNAS EN ORDEN C1 C2 C3
Keypad keypad = Keypad( makeKeymap(keys), pinsfilas, pinscolumnas, filas, columnas );
void setup(){
lcd.begin(20, 4);
}
void loop(){
while( millis() < timepofinaldisplay ) {
if( '#' == keypad.getKey() ) break;
}
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("PRUEBA DE OPCIONES");
lcd.setCursor(1, 1);
lcd.print("1. TEMPERATURA");
lcd.setCursor(1, 2);
lcd.print("2. HUMEDAD");
lcd.setCursor(1, 3);
lcd.print("3. ILUMINACION");
while ( (key = keypad.getKey() ) == NO_KEY );
switch (key){
case '1':
temperatura();
break;
case '2':
humedad();
break;
case '3':
iluminacion();
break;
}
}
void temperatura(){
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("PRUEBA DE OPCIONES");
lcd.setCursor(2, 3);
lcd.print("PULSA # PARA SALIR");
lcd.setCursor(5, 1);
lcd.print("TEMPERATURA");
lcd.setCursor(8, 2);
lcd.print("0,0");
timepofinaldisplay = millis() + 3000;
}
void humedad(){
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("PRUEBA DE OPCIONES");
lcd.setCursor(2, 3);
lcd.print("PULSA # PARA SALIR");
lcd.setCursor(5, 1);
lcd.print("HUMEDAD");
lcd.setCursor(8, 2);
lcd.print("0,0");
timepofinaldisplay = millis() + 3000;
}
void iluminacion(){
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("PRUEBA DE OPCIONES");
lcd.setCursor(2, 3);
lcd.print("PULSA # PARA SALIR");
lcd.setCursor(5, 1);
lcd.print("ILUMINACION");
lcd.setCursor(8, 2);
lcd.print("0,0");
timepofinaldisplay = millis() + 3000;
}