int buzzer = 13;
int counter = 0;
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
#define ledMerah 12
#define ledHijau 14
/* Comment this out to disable prints and save space */
#define BLYNK_TEMPLATE_ID "TMPL68FhvIJ98"
#define BLYNK_TEMPLATE_NAME "Latihan 6"
#define BLYNK_AUTH_TOKEN "pVvtomxjWE_86kgHUuCGZL6NbvNecm4k"
#define BLYNK_PRINT Serial
#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
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
digitalWrite(ledMerah, pinValue);
if(digitalRead(ledMerah) == HIGH){
counter1 += 1;
Blynk.virtualWrite(V5, counter1);
}
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
digitalWrite(ledHijau, pinValue);
if(digitalRead(ledHijau) == HIGH){
counter2 += 1;
Blynk.virtualWrite(V4, counter2);
}
}
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if (pinValue == 1)
{
digitalWrite(buzzer, HIGH);
tone(buzzer,100);
delay(500);
counter3 +=1;
Blynk.virtualWrite(V3, counter3);
}
else {
digitalWrite(buzzer, LOW);
noTone(buzzer);
delay(500);
}
// process received value
}
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(ledMerah, OUTPUT);
Blynk.begin(auth, ssid, pass);
pinMode(ledHijau, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop(){
Blynk.run();
}