#define BLYNK_TEMPLATE_ID "TMPL3_jMO6V4O"
#define BLYNK_TEMPLATE_NAME "Led"
#define BLYNK_AUTH_TOKEN "-8vOS7HsjEEYmHyJLKkiiLbzXyn02InO"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN; // Blynk Auth Token
char ssid[] = "Wokwi-GUEST"; // Wi-Fi SSID
char pass[] = ""; // Wi-Fi Password
const int ledPin = 5; // Set to GPIO 5 or any pin you're using
bool ledState = false; // Variable to store LED state
bool blinking = false; // Blinking state flag
unsigned long previousMillis = 0; // Store the last time LED was updated
const long interval = 500; // Interval for LED blink (500ms)
BLYNK_WRITE(V0) {
int pinValue = param.asInt(); // Get value from virtual pin V0
if (pinValue == 1) { // If switch is ON
blinking = true; // Start blinking
} else { // If switch is OFF
blinking = false; // Stop blinking
digitalWrite(ledPin, LOW); // Turn off LED
}
}
void setup() {
Serial.begin(115200); // Debug console
pinMode(ledPin, OUTPUT); // Initialize LED pin as output
Blynk.begin(auth, ssid, pass); // Connect to Blynk and Wi-Fi
}
void loop() {
Blynk.run(); // Run Blynk
// Blink the LED when blinking is true
if (blinking) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// If the LED is off, turn it on, and vice versa
ledState = !ledState;
digitalWrite(ledPin, ledState);
}
}
}