Prismatik FastLED WS2812B- Why first LED turns on automatically after several seconds after switching off backlight

I have a problem with the Arduino NANO configuration and WS2812B diodes. On Arduino 1.8.19 I threw FastLED 3.5.0 and the code below. Control via the Prismatik app. Basically everything works great until I want to turn off the backlight. A dozen or so seconds after turning off the backlight, the first LED turns on by itself. It does not matter whether I turn off the backlight with the button in the program or close the entire program. Sometimes it changes its color 1-2 times a second and sometimes it stays on the first color.

What could be the reason?

#include "FastLED.h"
#define NUM_LEDS 46
#define DATA_PIN 2

// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
#define serialRate 115200

// Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;

// Initialise LED-array

void setup() {
  // Use NEOPIXEL to keep true colors
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  // Initial RGB flash
  LEDS.showColor(CRGB(255, 0, 0));
  LEDS.showColor(CRGB(0, 255, 0));
  LEDS.showColor(CRGB(0, 0, 255));
  LEDS.showColor(CRGB(0, 0, 0));
  // Send "Magic Word" string to host

void loop() { 
  // Wait for first byte of Magic Word
  for(i = 0; i < sizeof prefix; ++i) {
    waitLoop: while (!Serial.available()) ;;
    // Check next byte in Magic Word
    if(prefix[i] == continue;
    // otherwise, start over
    i = 0;
    goto waitLoop;
  // Hi, Lo, Checksum  
  while (!Serial.available()) ;;;
  while (!Serial.available()) ;;;
  while (!Serial.available()) ;;;
  // If checksum does not match go back to wait
  if (chk != (hi ^ lo ^ 0x55)) {
    goto waitLoop;
  memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  // Read the transmission data and set LED values
  for (uint8_t i = 0; i < NUM_LEDS; i++) {
    byte r, g, b;    
    r =;
    g =;
    b =;
    leds[i].r = r;
    leds[i].g = g;
    leds[i].b = b;
  // Shows new values;

My guess is a hardware reason. Post a picture of the setup and a complete wiring diagram!

That label and the goto you use to jump at are working against the nature of the for loop.

goto is just strange there. A for statement is already a loop.

Later you goto the same label, but that is jumping into the body of the for loop, something that even fans of goto will tell you is asking for trouble.

There is no need to use goto. Review the syntax and operation of for, while and if statements and work out the logic with jumping. Of course I mean without jumping.

I am quite sure the odd behaviour is due to your odd logic… it might make sense to you, and another different kind of sense to the compiler.


In addtion to what @alto777 points, out, clearing the led array is not the proper way to make them all black. There is no guarantee there aren't other things under the hood

  //memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  fill_solid(leds, NUM_LEDS, CRGB::Black);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.