/*************************************************************
You’ll need:
- Blynk IoT app (download from App Store or Google Play)
- ESP32 board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL6ERD8mAOH"
#define BLYNK_DEVICE_NAME "Esp32 8 LED"
#define BLYNK_AUTH_TOKEN "zWJw8sklLl75KhoPEmd_ZzU7VCCGv6FI"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int ledPins[] = {15, 2, 4, 16, 17, 5, 18, 19};
int ledState = 0; // 0: LEDs OFF, 1: LEDs ON
BLYNK_WRITE(V0)
{
int switchValue = param.asInt();
if (switchValue == 1) {
ledState = 1;
} else {
ledState = 0;
}
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], ledState);
}
}
void setup()
{
Serial.begin(115200);
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW); // Matikan semua LED saat awalnya
}
Blynk.begin(auth, ssid, pass);
// Anda juga dapat menentukan server Blynk jika diperlukan.
// Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
// Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 1, 100), 8080);
}
void loop()
{
Blynk.run();
}