#define BLYNK_TEMPLATE_ID "TMPL6RYIU3TO-"
#define BLYNK_TEMPLATE_NAME "P5"
#define BLYNK_AUTH_TOKEN "52pqUVOytDfX30sdhS58qoIT1sy6X3-n"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define BLYNK_AUTH_TOKEN "52pqUVOytDfX30sdhS58qoIT1sy6X3-n"
#define SERVO_PIN_1 2
#define SERVO_PIN_2 4
#define LED_PIN 13
#define SWITCHER_PIN V1
Servo servo1;
Servo servo2;
bool isSwitcherOn = false;
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, WIFI_SSID, WIFI_PASSWORD);
servo1.attach(SERVO_PIN_1);
servo2.attach(SERVO_PIN_2);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
timer.setInterval(30000L, ledToggle);
Blynk.syncVirtual(SWITCHER_PIN); // Sinkronisasi status switcher pada awal program
}
void loop() {
Blynk.run();
timer.run();
}
void ledToggle() {
if (isSwitcherOn) {
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
}
}
BLYNK_WRITE(SWITCHER_PIN) {
int pinValue = param.asInt();
if (pinValue == 1) {
isSwitcherOn = true;
servo1.write(90);
servo2.write(90);
} else {
isSwitcherOn = false;
servo1.write(0);
servo2.write(0);
digitalWrite(LED_PIN, LOW);
}
}