#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const byte ROWS = 4; // Number of rows in the keypad
const byte COLS = 4; // Number of columns in the keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect keypad rows to these Arduino pins
byte colPins[COLS] = {5, 4, 3, 2}; // Connect keypad columns to these Arduino pins
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup() {
//Setup LCD wich backlight and initialize
lcd.begin(16, 2);
lcd.backlight();
lcd.init();
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
// Put your main code here, to run repeatedly:
char customKey = customKeypad.getKey();
if (customKey != NO_KEY) { // Check if a key is pressed
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Key Pressed:");
lcd.setCursor(0, 1);
lcd.print(customKey);
Serial.println(customKey);
}
}