#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Inisialisasi LCD I2C
LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat 0x27, LCD 16x2
// Konfigurasi Keypad
const byte ROWS = 4; // Jumlah baris pada keypad
const byte COLS = 4; // Jumlah kolom pada keypad
char keys[ROWS][COLS] = { // Layout tombol keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27}; // Pin baris pada ESP32
byte colPins[COLS] = {26, 25, 33, 32}; // Pin kolom pada ESP32
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Inisialisasi LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Keypad Input:");
}
void loop() {
char key = keypad.getKey(); // Membaca tombol yang ditekan
if (key) { // Jika ada tombol yang ditekan
lcd.setCursor(0, 1); // Pindah ke baris kedua
lcd.print("You Pressed: "); // Tampilkan pesan
lcd.print(key); // Tampilkan tombol yang ditekan
lcd.print(" "); // Hapus sisa karakter
delay(500); // Jeda sebelum membaca tombol berikutnya
}
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4