#define BLYNK_TEMPLATE_ID "TMPL6YRJEui7l"
#define BLYNK_TEMPLATE_NAME "test"
#define BLYNK_AUTH_TOKEN "TUsqOOEUyT4LOW-K1MB_JSUhtCiT9XrP"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int ledState = 0;
int buttonState = 0;
int pinLED = 2; // ใส่หมายเลขของพิน GPIO ที่เชื่อมกับ LED
int pinLED1 = 5;
int button = 14;
int pinLED2 = 26;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(pinLED, OUTPUT);
pinMode(pinLED1, OUTPUT);
pinMode(button, INPUT);
pinMode(pinLED2, OUTPUT);
}
void loop()
{
buttonState = digitalRead(button);
if(buttonState==0){
digitalWrite(pinLED,HIGH);
}
else{
digitalWrite(pinLED,LOW);
}
Blynk.run();
}
// ฟังก์ชั่นเปิด-ปิดไฟ LED ด้วยการกดปุ่มบนแอปพลิเคชัน Blynk
BLYNK_WRITE(V1)
{
int ledState = param.asInt();
if (ledState == 1) {
digitalWrite(pinLED, HIGH);
} else {
digitalWrite(pinLED, LOW);
}
}
BLYNK_WRITE(V3)
{
int ledState = param.asInt();
if (ledState == 1) {
digitalWrite(pinLED1, HIGH);
} else {
digitalWrite(pinLED1, LOW);
}
}