#define BLYNK_TEMPLATE_ID "TMPLOdxoDUBT"
#define BLYNK_DEVICE_NAME "Pet Monitoring System"
#define BLYNK_AUTH_TOKEN "wbs_b8Wh62Yp6gLrmfeETVN_9y-Ai7vb"
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int CLOSE_ANGLE = 90;
int OPEN_ANGLE = 0;
Servo servo1;
Servo servo2;
const int servoPin1 = 13;
const int servoPin2 = 12;
const int btnPin1 = 15;
const int btnPin2 = 2;
void PhysicalButton1();
void PhysicalButton2();
int btnState1 = LOW;
int btnState2 = LOW;
BLYNK_CONNECTED() {
Blynk.syncAll();
}
BLYNK_WRITE(V13)
{
int state = param.asInt();
if (state ==1)
{
servo1.write(OPEN_ANGLE);
int btnState1 =state;
}
else if (state ==0)
{
servo1.write(CLOSE_ANGLE);
int btnState1 =state;
}
}
BLYNK_WRITE(V14)
{
int state = param.asInt();
if (state ==1)
{
servo2.write(OPEN_ANGLE);
int btnState2 =state;
}
else if (state ==0)
{
servo2.write(CLOSE_ANGLE);
int btnState2 =state;
}
}
void PhysicalButton1()
{
int btnState1 = digitalRead(btnPin1);
if (btnState1 ==1)
{
servo1.write(OPEN_ANGLE);
}
else if (btnState1 ==0)
{
servo1.write(CLOSE_ANGLE);
}
}
void PhysicalButton2()
{
int btnState2 = digitalRead(btnPin2);
if (btnState2 ==1)
{
servo2.write(OPEN_ANGLE);
}
else if (btnState2 ==0)
{
servo2.write(CLOSE_ANGLE);
}
}
void setup() {
servo1.attach(servoPin1);
servo2.attach(servoPin2);
pinMode(btnPin1, INPUT);
pinMode(btnPin2, INPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
PhysicalButton1;
PhysicalButton2;
}
void loop() {
Blynk.run();
}