#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLWP_H4QUS"
#define BLYNK_DEVICE_NAME "Fish Feeder"
#define BLYNK_AUTH_TOKEN "QvdEPudMISkCpdWgdCOQzDev24uClQKo"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
//Blynk
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
//Servo
Servo servoku;
int SW_State=0;
int Posisi = 0;
BLYNK_WRITE (V0) //VO berfungsi utk menerima perintah dari App
{
Posisi = param.asInt(); //nilai dari widget ditangkap & disimpan dalam variable Posisi
if (Posisi >= 1)
{
servoku.write(Posisi);
delay(200);
Serial.println("Feeder HIDUP");
Blynk.virtualWrite(V13, "HIDUP"); //menulis status feeder ke widget GUI
Blynk.virtualWrite(V14, Posisi);
}
else
{
servoku.write(200);
Serial.println("Feeder MATI");
Blynk.virtualWrite(V13, "MATI");
}
}
/*
BLYNK_WRITE (V0)
{
Posisi = param.asInt();
servoku.write(Posisi);
}
*/
void setup () {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
servoku.attach(32);
servoku.write(0);
}
void loop()
{
Blynk.run();
servoku.write(200);
Blynk.virtualWrite(V14, "PAGI");
Blynk.virtualWrite(V13, "MATI");
delay(8000); /* sama dengan setiap 6 jam atau sehari 4 kali*/
servoku.write(120);
Blynk.virtualWrite(V13, "HIDUP");
Blynk.virtualWrite(V14, "PAGI");
delay(900);
servoku.write(200);
Blynk.virtualWrite(V14, "SIANG");
Blynk.virtualWrite(V13, "MATI");
delay(8000); /* sama dengan setiap 6 jam atau sehari 4 kali*/
servoku.write(120);
Blynk.virtualWrite(V13, "HIDUP");
Blynk.virtualWrite(V14, "SIANG");
delay(900);
servoku.write(200);
Blynk.virtualWrite(V14, "SORE");
Blynk.virtualWrite(V13, "MATI");
delay(8000); /* sama dengan setiap 6 jam atau sehari 4 kali*/
servoku.write(120);
Blynk.virtualWrite(V13, "HIDUP");
Blynk.virtualWrite(V14, "SORE");
delay(900);
servoku.write(200);
Blynk.virtualWrite(V14, "MALAM");
Blynk.virtualWrite(V13, "MATI");
delay(8000); /* sama dengan setiap 6 jam atau sehari 4 kali*/
servoku.write(120);
Blynk.virtualWrite(V13, "HIDUP");
Blynk.virtualWrite(V14, "MALAM");
delay(900);
}