//#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL68rzJYg63"
#define BLYNK_TEMPLATE_NAME "Esp32 4Led"
#define BLYNK_AUTH_TOKEN "UGXaUNhRRTWrFzGJg8mCVDAIjxkGHszm"
//--------------------------------------
// เลือกไลบรารีให้เหมาะกับแต่ละบอร์ด
//--------------------------------------
#if defined(ESP32)
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// ขา LED สำหรับ ESP32
int LED1 = 26;
int LED2 = 25;
int LED3 = 33;
int LED4 = 32;
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
// ขา LED สำหรับ ESP8266 (กำหนดให้ใช้ได้จริงบนบอร์ด)
int LED1 = 5; // D1 (GPIO5) RED
int LED2 = 4; // D2 (GPIO4) GREEN
int LED3 = 14; // D5 (GPIO14) BLUE
int LED4 = 12; // D6 (GPIO12) YELLOW
#endif
//--------------------------------------
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
void setup() {
Serial.begin(115200);
Serial.println("Connecting to Blynk...");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
Serial.println("System Ready");
}
void loop() {
Blynk.run();
}
//------------------------------------------------------
// Virtual Pin V1
//------------------------------------------------------
BLYNK_WRITE(V1) {
int v = param.asInt();
digitalWrite(LED1, v);
}
//------------------------------------------------------
// Virtual Pin V2
//------------------------------------------------------
BLYNK_WRITE(V2) {
int v = param.asInt();
digitalWrite(LED2, v);
}
//------------------------------------------------------
// Virtual Pin V3
//------------------------------------------------------
BLYNK_WRITE(V3) {
int v = param.asInt();
digitalWrite(LED3, v);
}
//------------------------------------------------------
// Virtual Pin V4
//------------------------------------------------------
BLYNK_WRITE(V4) {
int v = param.asInt();
digitalWrite(LED4, v);
}
//#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
/*
#define BLYNK_TEMPLATE_ID "TMPL68rzJYg63"
#define BLYNK_TEMPLATE_NAME "Esp32 4Led"
#define BLYNK_AUTH_TOKEN "UGXaUNhRRTWrFzGJg8mCVDAIjxkGHszm"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int LED1 = 26;
int LED2 = 25;
int LED3 = 33;
int LED4 = 32;
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Serial.println("OK");
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop() {
Blynk.run();
}
BLYNK_WRITE(V1) {
int pinValue = param.asInt(); // Get the value from the Blynk app
// Update LED state
if (pinValue == 1) {
digitalWrite(LED1, HIGH); // Turn LED ON
} else {
digitalWrite(LED1, LOW); // Turn LED OFF
}
}
BLYNK_WRITE(V2) {
int pinValue = param.asInt(); // Get the value from the Blynk app
// Update LED state
if (pinValue == 1) {
digitalWrite(LED2, HIGH); // Turn LED ON
} else {
digitalWrite(LED2, LOW); // Turn LED OFF
}
}
BLYNK_WRITE(V3) {
int pinValue = param.asInt(); // Get the value from the Blynk app
// Update LED state
if (pinValue == 1) {
digitalWrite(LED3, HIGH); // Turn LED ON
} else {
digitalWrite(LED3, LOW); // Turn LED OFF
}
}
BLYNK_WRITE(V4) {
int pinValue = param.asInt(); // Get the value from the Blynk app
// Update LED state
if (pinValue == 1) {
digitalWrite(LED4, HIGH); // Turn LED ON
} else {
digitalWrite(LED4, LOW); // Turn LED OFF
}
}
*/