// 22.11.4562 - Muhammad Guido Augusta
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int ledHijau = 2;
const int ledBiru = 3;
const int buttonHijau = 12;
const int buttonBiru = 11;
int buttonState = HIGH; // Status awal tombol (high karena menggunakan pull-up resistor)
int lastButtonState = HIGH; // Status tombol sebelumnya
int messageState = 0; // Status pesan
void setup() {
// put your setup code here, to run once:
pinMode(ledHijau, OUTPUT);
pinMode(ledBiru, OUTPUT);
pinMode(buttonHijau, INPUT);
pinMode(buttonBiru, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.begin(16, 2);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(buttonHijau) == 1) {
digitalWrite(ledHijau, HIGH);
} else {
digitalWrite(ledHijau, LOW);
}
int reading = digitalRead(buttonBiru); // Membaca status tombol
if (reading != lastButtonState) {
delay(50); // Debouncing
}
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
// Tombol ditekan
if (messageState == 0) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hello World");
messageState = 1;
} else if (messageState == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status Wi-Fi: ");
messageState = 2;
} else if (messageState == 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status Koneksi Blynk: ");
messageState = 0;
}
}
}
lastButtonState = reading; // Memperbarui status tombol sebelumnya
}