#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6nsDEfaka"
#define BLYNK_TEMPLATE_NAME "latihan 5"
#define BLYNK_AUTH_TOKEN "CDV5_NNIQw_I0g69aXr9umUSs7S4NReS"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <TM1637TinyDisplay.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
byte pushA = 2;
byte pushB = 4;
int counter = 0;
const int CLK = 19;
const int DIO = 18;
int space = 10;
TM1637TinyDisplay display(CLK, DIO);
BlynkTimer timer;
void sendSensor(){
display.showNumber(counter);
if(digitalRead(pushA)){
if(counter == 0 && space == 10){
delay(350);
Serial.print("\nJumlah Orang Mencapai Minimum : ");
Serial.println(counter);
Serial.print("Space Ruangan Masih Tersedia : ");
Serial.println(space);
Blynk.virtualWrite(V3, "Space Ruangan Tersedia");
}else{
counter--;
delay(350);
space += 1;
Serial.print("\nORANG KELUAR\n");
Serial.print("Jumlah Orang : ");
Serial.println(counter);
Blynk.virtualWrite(V4, counter);
Serial.print("Space : ");
Serial.println(space);
Blynk.virtualWrite(V5, space);
Blynk.virtualWrite(V3, "Space Ruangan Tersedia");
}
}else if (digitalRead(pushB)){
if(counter == 10 && space == 0 ){
delay(350);
Serial.print("\nJumlah Orang Mencapai Maksimum : ");
Serial.println(counter);
Serial.print("Space Ruangan habis : ");
Serial.println(space);
Blynk.virtualWrite(V3, "Space Ruangan habis");
}else{
counter++;
space -= 1;
Serial.print("\nORANG MASUK\n");
Serial.print("Jumlah Orang : ");
Serial.println(counter);
Blynk.virtualWrite(V4, counter);
Serial.print("Space : ");
Serial.println(space);
Blynk.virtualWrite(V5, space);
Blynk.virtualWrite(V3, "Space Ruangan Tersedia");
}
}
}
void setup() {
// put your setup code here, to run once:
display.setBrightness(0x0f);
display.setScrolldelay(100);
Serial.begin(115200);
pinMode(pushA, INPUT);
pinMode(pushB, INPUT);
Blynk.begin(auth, ssid, pass); //memulai Blynk
timer.setInterval(1000, sendSensor); //Mengaktifkan timer untuk pengiriman data 1000ms
}
void loop() {
Blynk.run(); //menjalankan blynk
timer.run(); //menjalankan timer
}