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.