#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "Wokwi-WiFi"; // Dummy WiFi untuk simulasi
const char* password = "12345678";
WebServer server(80);
#define LED_PIN 26 // Sebagai pengganti motor
#define SWITCH_PIN 14 // Saklar tekan (push button)
bool motorState = false; // Status motor
unsigned long lastPress = 0; // Waktu terakhir tombol ditekan
const int debounceDelay = 200; // Delay debounce (ms)
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(SWITCH_PIN, INPUT_PULLUP); // Gunakan internal pull-up
digitalWrite(LED_PIN, LOW); // Pastikan motor mati awalnya
WiFi.begin(ssid, password);
Serial.println("WiFi Dummy aktif");
server.on("/", []() {
server.send(200, "text/html",
"<h1>Dispenser Control</h1>"
"<a href='/on'><button>ON</button></a>"
"<a href='/off'><button>OFF</button></a>");
});
server.on("/on", []() {
motorState = true;
digitalWrite(LED_PIN, HIGH);
server.send(200, "text/html", "Motor Nyala");
});
server.on("/off", []() {
motorState = false;
digitalWrite(LED_PIN, LOW);
server.send(200, "text/html", "Motor Mati");
});
server.begin();
}
void loop() {
server.handleClient();
// Cek tombol untuk toggle
if (digitalRead(SWITCH_PIN) == LOW) { // Jika tombol ditekan
if (millis() - lastPress > debounceDelay) { // Debounce
motorState = !motorState; // Toggle motor
digitalWrite(LED_PIN, motorState ? HIGH : LOW);
Serial.println(motorState ? "Motor Nyala" : "Motor Mati");
lastPress = millis();
}
}
}