#include <Keypad.h>
#include <LiquidCrystal_I2C.h> // sertakan pustaka LCD I2C
const byte ROWS = 4; // Empat baris
const byte COLS = 4; // Empat kolom
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9};
byte colPins[COLS] = {2, 3, 4, 5};
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// --- Fungsi Setup ---
void setup(){
Serial.begin(9600);
pinMode(LED_BUILTIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT); // Mengatur LED internal (Pin 13) sebagai output
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
if (customKey == 'A' || customKey == 'B') {
Serial.println(customKey); }
// ... (letakkan seluruh logika kalkulator dan pembacaan keypad Anda di sini) ...
// Contoh output ke LCD I2C (baris 0 untuk input, baris 1 untuk hasil)
// Pastikan Anda memperbarui variabel ini dalam logika kalkulator Anda
String inputPengguna = "5+3";
float hasil = 8.0;
lcd setCursor(0, 1);
lcd print(inputPengguna);
lcd.setCursor(0, 1);
lcd.print("=");
lcd.print(hasil);
{
// Contoh output ke Serial Monitor
Serial.print("Input: ");
Serial.println(inputPengguna);
Serial.print("Hasil: ");
Serial.println(hasil);
}
lcd.setCursor(0, 1); // pindah kursor ke baris kedua (indeks 1)
lcd.print("Key: "); // tampilkan label
lcd.print(customKey); // tampilkan karakter tombol yang ditekan
// ---------------------------------------------------------
if (customKey == 'A' || customKey == 'B' ) {
digitalWrite(LED_BUILTIN, HIGH); // NYALAKAN LED internal (Pin 13)
} else {
digitalWrite(LED_BUILTIN, LOW); // MATIKAN LED internal
}
}
}