Virtual zeRGBa (to control ws2812b RGB) is not working

Recently I bought ws2812b LED strip and decided to make something cool with Blynk, NodeMCU and LEDs. The first idea was to change LEDs color with Blynk app. After one hour of reading I created a simple sketch which didn’t work out for me. Maybe someone can tell me what I’m doing wrong?

#include <Adafruit_NeoPixel.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define PIN 5

Adafruit_NeoPixel strip = Adafruit_NeoPixel(300, PIN, NEO_GRB + NEO_KHZ800);

 int alarmPinTop = 4;        
 int alarmPinBottom = 14;     
 int alarmValueTop = LOW;    
 int alarmValueBottom = LOW; 
 int R;                       // red
 int G;                       // green
 int B;                       // blue
 int Brightness;
 
  //===========================//
 //===*---*===Blynk===*---*===//
//===========================//

char auth[] = "f3***********************";
char ssid[] = "HUAWEI-*******";
char pass[] = "*************";

BLYNK_WRITE(V1) // zeRGBa assigned to V1 
{
    R = param[0].asInt();
    G = param[1].asInt();
    B = param[2].asInt();
}
BLYNK_WRITE(V2)
{
  int Brightness; = param.asInt();
}
 
 
void setup() {
   strip.begin();
   strip.setBrightness(Brightness);
   strip.show();
   Serial.begin (9600);
   pinMode(alarmPinTop, INPUT_PULLUP); 
   pinMode(alarmPinBottom, INPUT_PULLUP);
   pinMode(5, OUTPUT);
   Blynk.begin(auth, ssid, pass);
   delay(2000);
}

void loop() {

    Blynk.run();

    if (alarmPinBottom == LOW && alarmPinTop == LOW) {
       strip.setPixelColor(0, R, G, B);
       strip.setPixelColor(29, R, G, B);
       strip.setPixelColor(30, R, G, B);
       strip.setPixelColor(59, R, G, B);
       strip.setPixelColor(60, R, G, B);
       strip.setPixelColor(89, R, G, B);
       strip.setPixelColor(90, R, G, B);
       strip.setPixelColor(119, R, G, B);
       strip.setPixelColor(120, R, G, B);
       strip.setPixelColor(149, R, G, B);
       strip.setPixelColor(150, R, G, B);
       strip.setPixelColor(179, R, G, B);
       strip.setPixelColor(180, R, G, B);
       strip.setPixelColor(209, R, G, B);
       strip.setPixelColor(210, R, G, B);
       strip.setPixelColor(239, R, G, B);
       strip.setPixelColor(240, R, G, B);
       strip.setPixelColor(269, R, G, B);
       strip.setPixelColor(270, R, G, B);
       strip.setPixelColor(299, R, G, B);
       strip.show();     
  }
 }

two things:

  1. what do you mean with that? did your house burn down?
  2. the usual: do NOT put anything else ni your loop then blynk.run, timer.run and optionally: ota check routine. The rest goes in a seperate routine and on a timer. Do that first, if it still fails then: see 1. If you give a detailed description then we might be able to help.

Funny:D, but no. When I say didn’t work out I mean that nothing happens. Well thank you for information. I Will recreate my sketch later.

that’s still pretty vague, try adding some serial.println()'s in your code to check what is going on, which routines are run which not, what state is reached, what values are set, etc. and then report the log. Helps pin point the issue.

1 Like

Maybe you can tell me where is the best place to put all unnecessary code from void loop?

in a routine.

E.g.

void aRoutine(){
  if (alarmPinBottom == LOW && alarmPinTop == LOW) {
         strip.setPixelColor(0, R, G, B);
         serial.println("alarmpin bottom and top are both low, setting up strip"); //and you should add this stuff and check your serial monitor. although this line potentially can spam your serial monitor quite severely, so just use it to check if this routines actually ever runs.)
         ....
}

and then in void setup() you place a timer e.g.:

timer.setInterval(100, aRoutine); //which runs every 0.1 second
2 Likes