// Include LCD Library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Include Keypad Library
#include <Keypad.h>
// Define the LCD connections to the Arduino
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; // Number of rows on the keypad
const byte COLS = 4; // Number of columns on the keypad
// Define the keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Intializing the keypad connections to the Arduino with respective pins.
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {7, 6, 5, 4};
// Create the Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
}
void loop() {
// Get the key that was pressed
char key = keypad.getKey();
// If a key was pressed, print it to the LCD and the Serial Monitor
if (key != NO_KEY) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Key Pressed: ");
lcd.print(key);
}
}