#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4; // Number of keypad rows
const byte COLS = 4; // Number of keypad columns
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 ROW0, ROW1, ROW2, ROW3 to these Arduino pins
byte colPins[COLS] = {5, 4, 3, 2}; // Connect keypad COL0, COL1, COL2, COL3 to these Arduino pins
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
String text ; // Stores the inputted number
void setup() {
lcd.begin(16, 2);
lcd.backlight();
lcd.print("Enter Number:");
}
void loop() {
char key = keypad.getKey(); // Read the pressed key
if (key) {
if (key == '#') {
if (text.length() > 0) {
text.remove(text.length() - 1); // Remove the last character
lcd.setCursor(0, 1); // Set the cursor position on the LCD
lcd.print(" "); // Clear the previous text
lcd.setCursor(0, 1); // Set the cursor position again
lcd.print(text); // Display the updated text
}
} else {
text += key; // Append the pressed key to the text
lcd.setCursor(0, 1); // Set the cursor position on the LCD
lcd.print(text); // Display the updated text
}
}
}
// Make sure to include the necessary libraries (Keypad and LiquidCrystal_I2C) before uploading the code to your microcontroller. Adjust the pin assignments and I2C address for your specific setup if needed.