#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "KtKF7LTy8lTwn7MvadAQydFyyepfPkn6";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define LED_PIN_1 15
#define LED_PIN_2 18
#define LED_PIN_3 4
#define LED_PIN_4 5
#define RED_LED_PIN 2
int ledPins[] = {LED_PIN_1, LED_PIN_2, LED_PIN_3, LED_PIN_4};
bool ledStates[] = {false, false, false, false};
bool redLedState = false;
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
pinMode(RED_LED_PIN, OUTPUT);
digitalWrite(RED_LED_PIN, LOW);
}
void loop() {
Blynk.run();
}
BLYNK_WRITE(V1) {
int switchState = param.asInt();
ledStates[0] = switchState;
checkAllLeds();
digitalWrite(LED_PIN_1, switchState);
}
BLYNK_WRITE(V2) {
int switchState = param.asInt();
ledStates[1] = switchState;
checkAllLeds();
digitalWrite(LED_PIN_2, switchState);
}
BLYNK_WRITE(V3) {
int switchState = param.asInt();
ledStates[2] = switchState;
checkAllLeds();
digitalWrite(LED_PIN_3, switchState);
}
BLYNK_WRITE(V4) {
int switchState = param.asInt();
ledStates[3] = switchState;
checkAllLeds();
digitalWrite(LED_PIN_4, switchState);
}
void checkAllLeds() {
for (int i = 0; i < 4; i++) {
if (!ledStates[i]) {
redLedState = false;
digitalWrite(RED_LED_PIN, LOW);
Blynk.virtualWrite(V5,LOW);
return;
}
}
redLedState = true;
digitalWrite(RED_LED_PIN, HIGH);
Blynk.virtualWrite(V5,HIGH);
}