#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Inisialisasi LCD I2C (alamat 0x27)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Tombol
const int btnStart = 5; // Tombol MERAH
const int btnStop = 6; // Tombol BIRU
// LED indikator
const int ledRed = 4;
const int ledYellow = 3;
const int ledBlue = 2;
int state = 0; // 0 = standby, 1 = cooking, 2 = done
void setup() {
lcd.begin(16, 2); // <- FIXED: tambahkan ukuran LCD
lcd.backlight();
pinMode(btnStart, INPUT_PULLUP);
pinMode(btnStop, INPUT_PULLUP);
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledBlue, OUTPUT);
tampilkanStandby();
}
void loop() {
if (state == 0 && digitalRead(btnStart) == LOW) {
delay(50);
if (digitalRead(btnStart) == LOW) {
state = 1;
mulaiMemasak();
}
}
if (state != 0 && digitalRead(btnStop) == LOW) {
delay(50);
if (digitalRead(btnStop) == LOW) {
state = 2;
tampilkanSelesai();
delay(2000);
tampilkanStandby();
state = 0;
}
}
}
void mulaiMemasak() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Cooking...");
digitalWrite(ledRed, HIGH);
digitalWrite(ledYellow, LOW);
digitalWrite(ledBlue, LOW);
for (int i = 0; i <= 100; i++) {
if (digitalRead(btnStop) == LOW) break;
lcd.setCursor(0, 1);
lcd.print("Progress: ");
lcd.print(i);
lcd.print("% ");
delay(100);
}
state = 2;
tampilkanSelesai();
delay(2000);
tampilkanStandby();
state = 0;
}
void tampilkanStandby() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Microwave Ready");
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledBlue, HIGH);
}
void tampilkanSelesai() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Cooking Done!");
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, HIGH);
digitalWrite(ledBlue, LOW);
}