#include <LiquidCrystal.h>
#include <Keypad.h>
const int rs = 12; // Pin 7 on Arduino to pin 4 (RS) on LCD
const int en = 11; // Pin 6 on Arduino to pin 6 (E) on LCD
const int d4 = 10; // Pin 12 on Arduino to pin 11 (D4) on LCD
const int d5 = 9; // Pin 10 on Arduino to pin 12 (D5) on LCD
const int d6 = 8; // Pin 9 on Arduino to pin 13 (D6) on LCD
const int d7 = 7; // Pin 8 on Arduino to pin 14 (D7) on LCD // Pin 8 on Arduino to pin 14 (D7) on LCD
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] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { A0, A1, A2, A3}; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.begin(16, 2);
lcd.print("Masukkan Angka:");
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
static String input = ""; // variabel untuk menyimpan input
if (key >= '0' && key <= '9') { // hanya mengambil input angka
input += key; // tambahkan karakter ke variabel input
lcd.setCursor(0, 1);
lcd.print(input);
delay(100); // untuk menghindari bouncing keypad
}
else if (key == '#') { // menampilkan output pada tombol A
String output = ""; // variabel untuk menyimpan output
for (int i = input.length() - 1; i >= 0; i--) { // balik urutan karakter
output += input[i];
}
lcd.clear(); // hapus tampilan pada LCD
lcd.setCursor(0, 0);
lcd.print("Output: ");
lcd.setCursor(0, 1);
lcd.print(output); // tampilkan output
}
}
}