#include <Wire.h> // Library untuk komunikasi I2C
#include <LiquidCrystal_I2C.h> // Library untuk LCD dengan modul I2C
#include <Keypad.h> // Library untuk keypad
byte data_count = 0; // Variabel untuk menghitung jumlah karakter yang dimasukkan
const byte ROWS = 4; // Jumlah baris pada keypad
const byte COLS = 4; // Jumlah kolom pada keypad
// Mendefinisikan simbol pada tombol keypad
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'}, // baris pertama tombol
{'4','5','6','B'}, // baris kedua tombol
{'7','8','9','C'}, // baris ketiga tombol
{'*','0','#','D'} // baris keempat tombol
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // pin baris keypad (R1, R2, R3, R4)
byte colPins[COLS] = {5, 4, 3, 2}; // Pin Kolom Keypad (C1, C2, C3, C4)
// Inisialisasi keypad, membuat objek keypad dengan konfigurasi baris dan kolom
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// Inisialisasi LCD (membuat objek dengan alamat 0x27, 16 karakter, 2 baris)
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
// Inisialisasi LCD
lcd.init(); // inisialisasi LCD
lcd.backlight(); // Menghidupkan lampu belakang LCD
}
void loop() {
// put your main code here, to run repeatedly:
char customKey = customKeypad.getKey(); // membaca input dari keypad
if (customKey){ // jika tombol keypad di tekan
lcd.setCursor (data_count,0); // menetukan posisi kursor di baris kedua
lcd.print (customKey); // Menampilkan karakter yang di tekan pada LCD
data_count++; // Menambah hitungan karakter yang telah dimasukkan
}
}