#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Define the number of rows and columns in the keypad
const byte ROWS = 4;
const byte COLS = 4;
// Define the key mapping for the 4x4 keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Define the row and column pins of the keypad
byte rowPins[ROWS] = {15, 2, 0, 4};
byte colPins[COLS] = {16, 17, 5, 18};
// Create a Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD display
lcd.init();
lcd.backlight();
lcd.clear();
}
void loop() {
// Check if a key is pressed
lcd.clear();
char key = keypad.getKey();
if (key != NO_KEY) {
// Clear the LCD display
lcd.clear();
// Print the pressed key on the LCD display
lcd.print("Pressed Key: ");
lcd.print(key);
delay(1000);
}
}