#define BLYNK_TEMPLATE_ID "TMPL6Zh5w7I3y"
#define BLYNK_TEMPLATE_NAME "Sensor Lampu"
#define BLYNK_AUTH_TOKEN "BiH3mo3akdq1acFuh0qrfTjP6JjJNyGh"

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

char auth[] = "BiH3mo3akdq1acFuh0qrfTjP6JjJNyGh";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";

BlynkTimer timer;

#define LED 18
int SW_state = 0; //kondisi lampu mati

BLYNK_WRITE (V0)
{
  SW_state = param.asInt();
  if(SW_state == 1){
    digitalWrite(LED, HIGH);
    Serial.println("Lampu telah dihidupkan");
    Blynk.virtualWrite(V0, HIGH);
  }else{
    digitalWrite(LED, LOW);
    Serial.println("Lampu telah dimatikan");
    Blynk.virtualWrite(V0, LOW);
  }
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  Blynk.begin(auth, ssid, pass);
}
void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();
}