#include <Keypad.h>
#include <LiquidCrystal_I2C.h> // Include the LiquidCrystal_I2C library
// Define LCD connections
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16x2 display
const byte ROWS = 4; // Number of rows
const byte COLS = 4; // Number of columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {A0, A1, A2, A3}; // Connect to row pins
byte colPins[COLS] = {A4, A5, 2, 3}; // Connect to column pins
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputValue = "";
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the backlight
// Print initial message
lcd.setCursor(0, 0);
lcd.print("Enter: ");
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') {
// If '#' is pressed, clear the input value
inputValue = "";
} else {
// Append the pressed key to the input value
inputValue += key;
}
// Display the input value on the LCD
lcd.setCursor(7, 0); // Move cursor to the second row
lcd.print(" "); // Clear the previous input
lcd.setCursor(7, 0); // Move cursor to the second row
lcd.print(inputValue);
delay(200); // Add a small delay to debounce the keypad
}
}