#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Define the I2C address of the LCD
#define LCD_I2C_ADDRESS 0x3F
// Define the number of rows and columns in your keypad
const byte ROWS = 4;
const byte COLS = 4;
// Define the symbols on your keypad buttons
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Create a Keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), ROWS, COLS, ROWS, COLS);
// Create an LCD object
LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, 16, 2); // 16x2 LCD
void setup() {
Wire.begin(); // Initialize I2C communication
lcd.init(); // Initialize the LCD
lcd.backlight();
Serial.begin(9600);
}
void loop() {
char key = customKeypad.getKey(); // Read the keypad
if (key) {
lcd.setCursor(0, 1); // Set the cursor to the second line
lcd.print("DEDY ARYANTO " + String(key)); // Display the key on the LCD
Serial.println("DEDY ARYANTO" + String(key)); // Print the key to the serial monitor
delay(1000); // Delay for one second
lcd.clear(); // Clear the LCD screen
lcd.setCursor(1, 1); // Set the cursor to the second line
lcd.print("201020100027 " + String(key)); // Display the key on the LCD
Serial.println("201020100027" + String(key)); // Print the key to the serial monitor
delay(1000); // Delay for one second
lcd.clear(); // Clear the LCD screen
}
}