ESP8266: Virtual LEDs switch doesn't work

Hi everybody!
I wanted to make some virtual LEDs swith by pushing 1 button in the Blynk App. I try this simple sketch, but it doesn’t work anyway:

BLYNK_WRITE(3)
{
  if(param.asInt()){
    mode+=1;
    if(mode>2) mode=0;
    switch (mode){
      case 0://Ручной режим
      {led2.on();
      led3.off();
      led4.off();
      }
      break;
      
      case 1:
      {led2.off();
      led3.on();
      led4.off();      
      }
      break;
      
      case 2:
      {led2.off();
      led3.off();
      led4.on();      
      }
      break;
    }
}

}

Before the Setup block I post this:

WidgetLED led2(4);
WidgetLED led3(5);
WidgetLED led4(6);

When I push the V3 button it says, that ESP8266 is not in network. What’s wrong with my code?
Here is the full sketch:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "6b9e19debbf44e45824999a50ffe96a5";
WidgetLED led1(1);
WidgetLED led2(4);
WidgetLED led3(5);
WidgetLED led4(6);

int mode=1;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "pass");
}

void loop()
{
  Blynk.run();
}

BLYNK_WRITE(3)
{
  if(param.asInt()){
    mode+=1;
    if(mode>2) mode=0;
    switch (mode){
      case 0://Ручной режим
      {led2.on();
      led3.off();
      led4.off();
      }
      break;
      
      case 1:
      {led2.off();
      led3.on();
      led4.off();      
      }
      break;
      
      case 2:
      {led2.off();
      led3.off();
      led4.on();      
      }
      break;
    }
  }
}

Thanks.

Your code seems fine language-wise. I’m more thinking of something along the lines of your ESP not attached correctly or maybe not enough power? Can you post a bit details of your hardware setup because the software part looks ok.

Ok, I’ll post it a bit later.
Did you try my code on your ESP8266? Does it work correct?

Yep, I tried it (just now) and I can see what you are trying to accomplish. You want to light up the next led every time you push the button, right? Only your led1 doesn’t play along, but that is an easy fix in your code.

But yes, it works fine on my setup. ESP-01 on Arduino Mega as a shield.

1 Like

LED 1 doesn’t use in this sketch, I know it.
I try to launch this code on ESP-01 as Standalone. @Lichtsignaal Can you try it this way?
Thanks!

1 Like