#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Inisialisasi objek LCD dengan alamat I2C dan ukuran kolom dan baris
LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat I2C umumnya 0x27 untuk modul LCD
const int buttonPin = 2; // Pin yang terhubung ke tombol
int buttonState = 0; // Variabel untuk menyimpan status tombol sekarang
int lastButtonState = 0; // Variabel untuk menyimpan status tombol sebelumnya
void setup() {
lcd.init(); // Inisialisasi LCD
lcd.backlight(); // Aktifkan backlight LCD
pinMode(buttonPin, INPUT); // Set tombol sebagai input
}
void loop() {
buttonState = digitalRead(buttonPin); // Baca status tombol
// Tampilkan teks di LCD tergantung pada status tombol
if (buttonState == HIGH && lastButtonState == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tombol ditekan!");
} else if (buttonState == LOW && lastButtonState == HIGH) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tombol dilepas.");
}
lastButtonState = buttonState; // Simpan status tombol sebelumnya
}