#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
char key;
int dato;
//Definimos nuestro teclado matricial
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
pinMode (13, OUTPUT);
digitalWrite (13, LOW);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("Bienvenido");
delay(3000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Seleccione menu");
lcd.setCursor(0, 2);
lcd.print("mediante su teclado");
delay(3000);
lcd.clear();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("1.Control Manual");
lcd.setCursor(0, 1);
lcd.print("2.Control Automatico");
lcd.setCursor(0, 2);
lcd.print("3.Clima");
key = keypad.getKey();
if (key) {
///////////////////////////////Configuración del primer botón
if (key == '1') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1.Encender Bomba");
lcd.setCursor(0, 1);
lcd.print("2.Apagar Bomba");
lcd.setCursor(0, 2);
lcd.print("3.Volver al menu");
dato = 1;
while (dato) {
key = keypad.getKey();
if (key == '1') {
digitalWrite (13, HIGH);
lcd.setCursor(0, 3);
lcd.print("Bomba ON!");
}
if (key == '2') {
digitalWrite (13, LOW);
lcd.setCursor(0, 3);
lcd.print("Bomba OFF");
}
if (key == '3') {
dato = 0;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("RETORNANDO");
lcd.setCursor(11, 2);
lcd.print("A");
lcd.setCursor(13, 3);
lcd.print("MENU");
delay(2000);
lcd.clear();
key = 0;
}
}
}
//////////////////////// Configuración del segundo botón
if (key == '2') {
lcd.clear();
dato = 1;
while (dato) {
lcd.setCursor(3, 1);
lcd.print("AUTOMATICO");
lcd.setCursor(3, 2);
lcd.print("3.Menu Principal");
key = keypad.getKey();
if (key == '3') {
dato = 0;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("RETORNANDO");
lcd.setCursor(11, 2);
lcd.print("A");
lcd.setCursor(13, 3);
lcd.print("MENU");
delay(2000);
lcd.clear();
key = 0;
}
}
}
}//cierre
}