#include <Keypad.h>
#include <LiquidCrystal.h>
int pin1 = 27;
LiquidCrystal lcd(22,23,5,18,19,21);
const uint8_t fil = 4; //dim fila
const uint8_t colum = 4; //dim col
//distribución
char teclas[fil][colum] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// pines correspondientes a las filas
//RX2 es el pin 16 y TX2 pin 17
uint8_t colPins[colum] = { 16, 4, 2, 15 };
// pines correspondientes a las columnas
uint8_t filPins[fil] = { 14, 12, 13, 17 };
// crea objeto con los parametros
Keypad teclado = Keypad(makeKeymap(teclas), filPins, colPins, fil, colum);
void setup() {
Serial.begin(9600);
pinMode(pin1, OUTPUT);
}
void loop() {
char tecla = teclado.getKey(); //obtiene variable
if (tecla) {
lcd.setCursor(0,0);
lcd.clear();
lcd.print(tecla);
Serial.println(tecla);
}
if (tecla == 'A'){
digitalWrite(pin1, HIGH);
}
if (tecla == 'B'){
digitalWrite(pin1, LOW);
}
}