#define BLYNK_PRINT Serial
//#include <SimpleTimer.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
/* Fill in information from Blynk Device Info here */
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
//#define BLYNK_TEMPLATE_NAME "Device"
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
#define BLYNK_TEMPLATE_ID "TMPL4XFGw_y_"
#define BLYNK_TEMPLATE_NAME "ESP32LED"
#define BLYNK_AUTH_TOKEN "0rO_1V4QqXruYwg1ohnOlMXRA5_JSJti"
char auth[] = BLYNK_AUTH_TOKEN; // ใส่ Auth Token ของ Blynk ที่ได้รับจากแอปพลิเคชัน Blynk
char ssid[] = "Wokwi-GUEST"; // ใส่ชื่อ WiFi ที่ต้องการเชื่อมต่อ
char pass[] = ""; // ใส่รหัสผ่าน WiFi ที่ต้องการเชื่อมต่อ
int pinLED = 2; // ใส่หมายเลขของพิน GPIO ที่เชื่อมกับ LED
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(pinLED, OUTPUT);
timer.setInterval(1000L, sensor1);
}
void loop()
{
Blynk.run();
timer.run();
}
void sensor1(){
potValue = analogRead(potPin);
Serial.println(potValue);
Blynk.virtualWrite(V1, potValue);
}
// ฟังก์ชั่นเปิด-ปิดไฟ LED ด้วยการกดปุ่มบนแอปพลิเคชัน Blynk
BLYNK_WRITE(V0)
{
int ledState = param.asInt();
if (ledState == 1) {
digitalWrite(pinLED, HIGH);
} else {
digitalWrite(pinLED, LOW);
}
}