/*
Blynk example
You should get Auth Token in the Blynk App.
You need to write the right wifiCredentials.
*/
/* Comment this out to disable prints and save space */
#define BLYNK_TEMPLATE_ID "TMPL6DrPIrp9W"
#define BLYNK_TEMPLATE_NAME "LED CONS"
#define BLYNK_AUTH_TOKEN "Ns8gsYCVj4S0hb6OjPgBalbdF0fVh6XV"
#define BLYNK_PRINT Serial
int buzzer = 0;
int totmasuk = 0;
int totkeluar = 0;
int totken = 20;
int eventTrigger = 0;
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
void cetak() {
float totalklik = totmasuk + totkeluar + buzzer;
if(totalklik >= totken){
Blynk.virtualWrite(V7,"Token Sudah Habis Dipakai");
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V1,0);
Blynk.virtualWrite(V2,0);
}else{
Blynk.virtualWrite(V7," ");
}
Serial.println("Jumlah LED hijau : " + String(totmasuk));
Blynk.virtualWrite(V3, totmasuk);
Serial.println("Jumlah LED merah : " + String(totkeluar));
Blynk.virtualWrite(V4, totkeluar);
Serial.println("Jumlah Buzzer : " + String(buzzer));
Blynk.virtualWrite(V5, buzzer);
Serial.println("------------------------------");
Blynk.virtualWrite(V6,totalklik);
}
BLYNK_WRITE(V0)
{
float totalklik = totmasuk + totkeluar + buzzer;
if(totalklik >= totken){
digitalWrite(15, LOW);
}
else{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(15, HIGH);
totmasuk++;
cetak();
}
else{
digitalWrite(15, LOW);
}
}
}
BLYNK_WRITE(V1)
{
float totalklik = totmasuk + totkeluar + buzzer;
if(totalklik >= totken){
digitalWrite(2, LOW);
}
else{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(2, HIGH);
totkeluar++;
cetak();
}
else{
digitalWrite(2, LOW);
}
}
}
BLYNK_WRITE(V2)
{
float totalklik = totmasuk + totkeluar + buzzer;
if(totalklik >= totken){
noTone(4);
}
else{
int pinValue = param.asInt();
if (pinValue == 1)
{
tone(4,500);
buzzer++;
cetak();
}
else{
noTone(4);
}
}
}
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(15, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
}