#define BLYNK_TEMPLATE_ID           "TMPL6aBQ617N1"
#define BLYNK_TEMPLATE_NAME         "Quickstart Template"
#define BLYNK_AUTH_TOKEN            "KDMZguQS-wacyBbK8sgpSEEaV4wmJby9"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
const int pb = 14;
const int relay = 15;
const int relay2 = 19;
const int Floor1 = 18;
const int Floor2 = 21;
const int Floor3 = 22;
const int Floor4 = 23;
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int i = 0;
int c = 0;
int a =0;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";

BlynkTimer timer;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  int value = param.asInt();
  if (value == HIGH) {
    for(i=0;i<c;i++){
    digitalWrite(relay2, HIGH);
    delay(500);
    digitalWrite(relay2, LOW);
    delay(500);
    }
    c = 0;
    Serial.println((c));
  } else {
    digitalWrite(relay2, LOW);
  }
}

BLYNK_WRITE(V1)
{
  int value1 = param.asInt();
  if (value1 == HIGH) {
    if(c>1){
      a=c-1;
      for (i=0;i <a;i++){
       digitalWrite(relay2, HIGH);
       delay(500);
       digitalWrite(relay2, LOW);
       delay(500);
      }
   }
   if(c<1){
      a=1-c;
      for(i=0;i<a;i++){
        digitalWrite(relay, HIGH);
        delay(500);
        digitalWrite(relay, LOW);
        delay(500);
      }
    }
    digitalWrite(Floor1, HIGH);
    for(i=0;i<a;i++){
      digitalWrite(relay, HIGH);
      delay(500);
      digitalWrite(relay, LOW);
      delay(500);


    }
    c=1;
    Serial.println((c));
    delay(500);

  } else {
    digitalWrite(relay, LOW);
    digitalWrite(Floor1, LOW);
    digitalWrite(relay2, LOW);
  }
}

BLYNK_WRITE(V5)
{
  int value2 = param.asInt();
  if (value2 == HIGH) {
    if(c>2){
      a=c-2;
      for(i=0;i<a;i++){
        digitalWrite(relay2, HIGH);
        delay(500);
        digitalWrite(relay2, LOW);
        delay(500);
      }
    }
    if(c<2){
      a=2-c;
      for(i=0;i<a;i++){
      digitalWrite(relay, HIGH);
      delay(500);
      digitalWrite(relay, LOW);
      delay(500);
      }
    }
    c = 2;
    digitalWrite(Floor2, HIGH);
    Serial.println((c));
    delay(500);
  } else {
    digitalWrite(relay, LOW);
    digitalWrite(Floor2, LOW);
  }
}
BLYNK_WRITE(V3)
{
  int value3 = param.asInt();
  if (value3 == HIGH) {
    if(c>3){
      a= c-3;
      for(i=0;i<a;i++){
      digitalWrite(relay2,HIGH);
      delay(500);
      digitalWrite(relay, LOW);
      delay(500);
      }
    }
    if(c<3){
      a=3-c;
      for(i=0;i<a;i++){
      digitalWrite(relay, HIGH);
      delay(500);
      digitalWrite(relay, LOW);
      delay(500);
      }
    }
    c = 3;
    digitalWrite(Floor3, HIGH);
    Serial.println((c));
    delay(500);

  } else {
    digitalWrite(relay, LOW);
    digitalWrite(Floor3, LOW);
  
  }
}

BLYNK_WRITE(V4)
{
  int value4 = param.asInt();
  if (value4 == HIGH) {
    if(c>4){
      a=c-4;
      for(i=0;i<a;i++){
      digitalWrite(relay2, HIGH);
      delay(500);
      digitalWrite(relay2,LOW);
      delay(500);
      }
    }
    if(c<4){
      a=4-c;
      for(i=0;i<a;i++){
      digitalWrite(relay, HIGH);
      delay(500);
      digitalWrite(relay, LOW);
      delay(500);
      }
    }
    c = 4;
    Serial.println((c));
    digitalWrite(Floor4, HIGH);
    delay(500);
  } else {
    digitalWrite(relay, LOW);
    digitalWrite(Floor4, LOW);
  }
}

BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more than 10 values per second.
  Blynk.virtualWrite(V2, millis() / 1000);
}

void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println(" Connected!");
  // Debug console
  pinMode(pb, INPUT_PULLUP);
  pinMode(relay, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(Floor1, OUTPUT);
  pinMode(Floor2, OUTPUT);
  pinMode(Floor3, OUTPUT);
  pinMode(Floor4, OUTPUT);
  digitalWrite(relay2, LOW);
  digitalWrite(relay, LOW);
  digitalWrite(Floor1, LOW);
  digitalWrite(Floor2, LOW);
  digitalWrite(Floor3, LOW);
  digitalWrite(Floor4, LOW);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}
$abcdeabcde151015202530fghijfghij
$abcdeabcde151015202530354045505560fghijfghij
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module