#include <Wire.h> // Library untuk komunikasi I2C
#include <LiquidCrystal_I2C.h> // Library untuk LCD I2C
#include <Keypad.h> // Library untuk Keypad
// Inisialisasi LCD dengan alamat I2C (misal: 0x27) dan ukuran 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Konfigurasi Keypad 4x4
const byte ROWS = 4; // 4 baris pada keypad
const byte COLS = 4; // 4 kolom pada 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}; // Pin Arduino yang terhubung ke baris Keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Pin Arduino yang terhubung ke kolom Keypad
// Inisialisasi keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.init(); // Inisialisasi LCD
lcd.backlight(); // Mengaktifkan lampu latar LCD
lcd.setCursor(0, 0); // Set posisi kursor LCD
lcd.print("Input Keypad:"); // Menampilkan pesan awal di LCD
}
void loop() {
char key = keypad.getKey(); // Membaca input dari keypad
if (key) { // Jika ada tombol yang ditekan
lcd.setCursor(0, 1); // Pindah kursor ke baris kedua LCD
lcd.print("Key Pressed: "); // Menampilkan teks di baris kedua
lcd.print(key); // Menampilkan karakter yang ditekan
delay(500); // Jeda 500ms
lcd.clear(); // Menghapus tampilan LCD
lcd.setCursor(0, 0); // Set kursor ke posisi awal
lcd.print("Input Keypad:"); // Menampilkan pesan awal lagi
}
}