// Importa LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2); // SET LCD
// importa libreria Keypad
#include <Keypad.h>
// define numero de filas
const uint8_t ROWS = 4;
// define numero de columnas
const uint8_t COLS = 4;
// define la distribucion de teclas
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// pines correspondientes a las filas
uint8_t colPins[COLS] = { 16, 4, 2, 15 };
// pines correspondientes a las columnas
uint8_t rowPins[ROWS] = { 19, 18, 5, 17 };
// crea objeto con los prametros creados previamente
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String linea1 = "";
String linea2 = "";
void inicio(){
linea1 = "INGRESE SU CLAVE";
linea2 = "Y PRESIONE [A] ";
LCD.setCursor(0, 0);
LCD.print(linea1);
LCD.setCursor(0, 1);
LCD.print(linea2);
linea1 = "";
linea2 = "";
}
void setup() {
Serial.begin(9600);
LCD.init();
LCD.backlight();
inicio();
}
void loop() {
// obtiene tecla presionada y asigna a variable
char key = keypad.getKey();
// comprueba que se haya presionado una tecla
if (key) {
LCD.clear();
if (key == 'C') {
linea1 = " ";
LCD.setCursor(0, 0);
LCD.print(linea1);
linea1 = "";
inicio();
}
if ((key != 'C') && (key != 'A')) {
linea1 = linea1 + key;
// envia a monitor serial la tecla presionada
Serial.println(key);
Serial.println(linea1);
LCD.setCursor(0, 0);
LCD.print(linea1);
}
if (key == 'A'){
linea1 = "CLAVE ACEPTADA";
linea2 = "SALDO: Bs. 215";
LCD.setCursor(0, 0);
LCD.print(linea1);
LCD.setCursor(0, 1);
LCD.print(linea2);
delay(3000);
inicio();
}
}
}