// belum jalan
#include <WiFi.h>
#include <WebServer.h>
#include <AccelStepper.h>
#include <LiquidCrystal_I2C.h>
// KONFIGURASI PIN
const int stepL = 12;
const int dirL = 14;
const int stepR = 17;
const int dirR = 16;
const int pinIRL = 32;
const int pinIRC = 33;
const int pinIRR = 35;
const int trigPin = 5;
const int echoPin = 18;
const int btnPin = 34;
// OBJEK & PEMUBAH
AccelStepper stepperL(1, stepL, dirL);
AccelStepper stepperR(1, stepR, dirR);
LiquidCrystal_I2C lcd(0x27,16,2);
WebServer server(80);
bool isMoving = false;
int threshold = 500;
String statusRobot = "Sedia Menerima Tugas";
String destination = "Tiada"; // Ini selesaikan ralat 'not declared'
// WEB INTERFACE
void setupServer(){
server.on("/", [](){
String html = "<html><head><meta name='viewport' content='width=device-width, initial-scale=1'>";
html += "<style>body{font-family:sans-serif; text-align:center; background:#f0f2f5; padding:20px;}";
html += ".card{background:white; max-width:350px; margin:auto; padding:25px; border-radius:20px; box-shadow:0 10px 25px rgba(0,0,0,0.1);}";
html += ".status{background:#d1e7ff; color:#004085; padding:15px; border-radius:10px; margin:15px 0; font-weight:bold;}";
html += ".btn{display:block; padding:15px; margin:10px 0; border:none; border-radius:10px; color:white; font-weight:bold; cursor:pointer; text-decoration:none;}";
html += ".btn-blue{background:#007bff;} .btn-purple{background:#6f42c1;} .btn-orange{background:#fd7e14;}";
html += "</style></head><body><div class='card'>";
html += "<h2>🤖 Robot Menu</h2>";
html += "<div class='status'>STATUS: " + statusRobot + "</div>";
html += "<a href='/go?dest=Meja A' class='btn btn-blue'>HANTAR KE MEJA A</a>";
html += "<a href='/go?dest=Meja B' class='btn btn-purple'>HANTAR KE MEJA B</a>";
html += "<hr><a href='/go?dest=Docking' class='btn btn-orange'>BALIK KE DOCKING</a>";
html += "</div></body></html>";
server.send(200, "text/html", html);});
server.on("/go", [](){
destination = server.arg("dest");
statusRobot = "Sedang ke " + destination;
isMoving = true;
server.send(200, "text/html", "<script>location.href='/';</script>");});
server.begin();}
void setup(){
Serial.begin(115200);
pinMode(pinIRL, INPUT);
pinMode(pinIRC, INPUT);
pinMode(pinIRR, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(btnPin, INPUT_PULLUP);
stepperL.setMaxSpeed(1000);
stepperR.setMaxSpeed(1000);
lcd.init(); lcd.backlight();
WiFi.begin("Wokwi-GUEST", "");
while (WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");}
setupServer();
lcd.clear(); lcd.print("Robot Online");}
void loop(){
server.handleClient();
if(isMoving){
// Logik gerak motor (Forward)
stepperL.setSpeed(600); stepperR.setSpeed(600);
stepperL.runSpeed(); stepperR.runSpeed();}
else{
stepperL.setSpeed(0); stepperR.setSpeed(0);
stepperL.runSpeed(); stepperR.runSpeed();}
if(digitalRead(btnPin) == LOW){
isMoving = false;
statusRobot = "Tugas Selesai";}}