#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "TMPL6kQqrFm4N"
#define BLYNK_TEMPLATE_NAME "Basic Blynk"
#define BLYNK_AUTH_TOKEN "LuFuz79S0sPXsdf21hrdD5fa9qWa9mD_"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

int pinRelay = 12;
int PU = 13;
int PB = 14;
int statusPU = 0;
int statusPB = 0;

char ssid[] = "Wokwi-GUEST"; //ganti sesuai hotspot/wifi yang tersedia
char pass[] = "";

BlynkTimer timer;

BLYNK_WRITE(V0)
{
 int pinValue = param.asInt();
 digitalWrite(pinRelay, !pinValue);
}

void sendData(){
    statusPU = digitalRead(PU);
    if (statusPU == LOW)
    {
      Blynk.virtualWrite(V1, "TERBUKA");
      Blynk.virtualWrite(V3, statusPU);
    }
  else
    {
      Blynk.virtualWrite(V1, "TERTUTUP");
      Blynk.virtualWrite(V3, statusPU);
    }

    statusPB = digitalRead(PB);
    if (statusPB == LOW)
    {
      Blynk.virtualWrite(V2, "TERBUKA");
      Blynk.virtualWrite(V4, statusPB);
    }
  else
    {
      Blynk.virtualWrite(V2, "TERTUTUP");
      Blynk.virtualWrite(V4, statusPB);
    }
  }

void setup() {
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  pinMode(pinRelay, OUTPUT);
  pinMode(PU, INPUT_PULLUP);
  pinMode(PB, INPUT_PULLUP);
  timer.setInterval(200L, sendData);
}

void loop() {
  Blynk.run();
  timer.run();
}