#define BLYNK_TEMPLATE_ID "TMPL6aBQ617N1"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "18ov9JDjhzY_5yvR4QzciKGIkEVep1xY"
#define led 21
#define poten 34
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
const int servoPin = 23;
Servo servo;
const char* ssid = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
int value1 = param.asInt();
if(value1==1){
digitalWrite(led, HIGH);
delay(15);
}else{
digitalWrite(led, LOW);
delay(15);
}
}
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V3)
{
int value = param.asInt();
if(value==1){
servo.write(90);
delay(15);
}else{
servo.write(180);
delay(15);
}
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
servo.attach(servoPin);
Serial.begin(115200);
delay(10);
Serial.println('\n');
Serial.begin(115200);
WiFi.softAP(ssid, pass); // Start the access point
Serial.print("Access Point \"");
Serial.print(ssid);
Serial.println("\" started");
Serial.print("IP address:\t");
Serial.println(WiFi.softAPIP());
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
int a =analogRead(poten);
Serial.println((a));
delay(20);
Blynk.virtualWrite(V1, a);
if (a >= 2000){
Blynk.virtualWrite(V2, 1);
}
else if (a < 2000){
Blynk.virtualWrite(V2, 0);
}
Blynk.run();
timer.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}