#include <LiquidCrystal.h>
#include <Keypad.h>
const int rs = 12; // Pin 12 on Arduino to pin 4 (RS) on LCD
const int en = 11; // Pin 11 on Arduino to pin 6 (E) on LCD
const int d4 = 10; // Pin 10 on Arduino to pin 11 (D4) on LCD
const int d5 = 9; // Pin 9 on Arduino to pin 12 (D5) on LCD
const int d6 = 8; // Pin 8 on Arduino to pin 13 (D6) on LCD
const int d7 = 7; // Pin 7 on Arduino to pin 14 (D7) on LCD // Pin 8 on Arduino to pin 14 (D7) on LCD
LiquidCrystal lcd (rs,en,d4,d5,d6,d7);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { A0, A1, A2, A3}; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.begin(16,2);
lcd.print("Test Keypad");
delay (1000);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
lcd.clear();
lcd.print("Key:");
lcd.print(key);
}
}