#define BLYNK_TEMPLATE_ID "TMPL6HMEx7lxe"
#define BLYNK_TEMPLATE_NAME "Trafic Light Ambulance"
#define BLYNK_AUTH_TOKEN "Ew7J13-YFxg5uXCxz-oFx0kd98NVn_Xw"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define hijau1 23
#define kuning 22
#define merah1 21
#define hijau2 19
#define merah2 18
#define hijau3 5
#define merah3 4
#define alarm 12
int data;
int a;
BLYNK_WRITE(V0)
{
data = param.asInt();
if(data == 1){
a = 1;
Blynk.virtualWrite(V2, "Lampu Hijau Dari Arah Kairagi");
digitalWrite (kuning, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (hijau2, LOW);
digitalWrite (hijau3, LOW);
digitalWrite (merah1, LOW);
digitalWrite (merah2, LOW);
digitalWrite (merah3, LOW);
delay(3000);
digitalWrite (kuning, LOW);
digitalWrite (hijau1, HIGH);
digitalWrite (merah2, HIGH);
digitalWrite (merah3, HIGH);
}
else{
a = 0;
}
}
void setup() {
// put your setup code here, to run once:
pinMode (hijau1, OUTPUT);
pinMode (hijau2, OUTPUT);
pinMode (hijau3, OUTPUT);
pinMode (merah1, OUTPUT);
pinMode (merah2, OUTPUT);
pinMode (merah3, OUTPUT);
pinMode (kuning, OUTPUT);
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0, 0);
}
void loop() {
Blynk.run();
if (a == 1){
Blynk.virtualWrite(V1, "Ambulance Silahkan Lewat");
}else{
Blynk.virtualWrite(V1, "Trafic Light Normal");
digitalWrite (kuning, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (hijau2, LOW);
digitalWrite (hijau3, LOW);
digitalWrite (merah1, LOW);
digitalWrite (merah2, LOW);
digitalWrite (merah3, LOW);
delay(2000);
Blynk.virtualWrite(V2, "Lampu Hijau Dari Perkamil");
digitalWrite (kuning, LOW);
digitalWrite (merah1, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (merah2, LOW);
digitalWrite (hijau2, HIGH);
digitalWrite (merah3, HIGH);
digitalWrite (hijau3, LOW);
delay(5000);
digitalWrite (kuning, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (hijau2, LOW);
digitalWrite (hijau3, LOW);
digitalWrite (merah1, LOW);
digitalWrite (merah2, LOW);
digitalWrite (merah3, LOW);
delay(2000);
Blynk.virtualWrite(V2, "Lampu Hijau Dari Arah Pusat Kota");
digitalWrite (kuning, LOW);
digitalWrite (merah1, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (merah2, HIGH);
digitalWrite (hijau2, LOW);
digitalWrite (merah3, LOW);
digitalWrite (hijau3, HIGH);
delay(5000);
digitalWrite (kuning, HIGH);
digitalWrite (hijau1, LOW);
digitalWrite (hijau2, LOW);
digitalWrite (hijau3, LOW);
digitalWrite (merah1, LOW);
digitalWrite (merah2, LOW);
digitalWrite (merah3, LOW);
delay(2000);
Blynk.virtualWrite(V2, "Lampu Hijau Dari Arah Kairagi");
digitalWrite (kuning, LOW);
digitalWrite (merah1, LOW);
digitalWrite (hijau1, HIGH);
digitalWrite (merah2, HIGH);
digitalWrite (hijau2, LOW);
digitalWrite (merah3, HIGH);
digitalWrite (hijau3, LOW);
delay(5000);
}
}