#include <LiquidCrystal.h>
#include <Keypad.h>
// Define the pins for the LCD screen
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// Define the pins for the keypad
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {14, 15, 16, 17};
// Define the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Initialize the LCD screen
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Press a key:");
// Initialize the serial monitor
Serial.begin(9600);
}
void loop() {
// Read the keypad
char key = keypad.getKey();
if (key != NO_KEY) {
// Display the pressed key on the LCD screen
lcd.setCursor(0, 1);
lcd.print(key);
// Print the pressed key to the serial monitor
Serial.println(key);
delay(200); // Debounce the keypad
}
}