BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Can add multiple LED with delay blink


#1

I can’t add more LED with delay blink.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

WidgetLED led1(D7);
WidgetLED ledBlinking(D5);
#define LED_PINBLINK D5
int t1;
BlynkTimer timer;

// V1 LED Widget is blinking
void blinkLedWidget()
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on D7: off");
  } else {
    led1.on();
    Serial.println("LED on D7: on");
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  timer.setInterval(1000L, blinkLedWidget);
  pinMode(LED_PINBLINK, OUTPUT);
  t1 = timer.setInterval(1000, ledBlynk);
  timer.disable(t1);
}

BLYNK_WRITE(1)
{
  if (param.asInt()) {
    timer.enable(t1);
  } else {
    timer.disable(t1);
    digitalWrite(LED_PINBLINK, LOW);
  }
}

// Change blink interval using virtual pin 2
BLYNK_WRITE(2)
{
  int interval = param.asInt();
  boolean wasEnabled = timer.isEnabled(t1);
  timer.deleteTimer(t1);
  t1 = timer.setInterval(interval, ledBlynk);
  if (!wasEnabled) {
    timer.disable(t1);
  }
}
void ledBlynk()
{
  digitalWrite(LED_PINBLINK, !digitalRead(LED_PINBLINK));
}
void loop()
{
  Blynk.run();
  timer.run();
}

#2

You also cannot properly format posted code… so I fixed your post as per the directions

As for your question… what is your question :stuck_out_tongue:


#3

You can create as many blinking leds as you like
use “case” statement and a flag into the void blinkLedWidget()
:wink: