#include <LiquidCrystal.h>
#include <Keypad.h>
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 3, 2, 1, 0 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 7, 6, 5, 4 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String currentInput = ""; // Variabel untuk menyimpan input saat ini
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Taufik");
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key == 'C') {
// Tombol "C" ditekan, maka hapus karakter terakhir
if (currentInput.length() > 0) {
currentInput = currentInput.substring(0, currentInput.length() - 1);
}
} else {
currentInput += key;
}
lcd.setCursor(0, 1);
lcd.print(" "); // Hapus tampilan sebelumnya
lcd.setCursor(0, 1);
lcd.print(currentInput);
}
}