FastLED sketch compiles but display is wrong

I want to display a binary number on a short strip of WS2812B led's, which is just ten pixels long for now. The entire circuit is an Arduino Uno with +5v, ground and pin 5 for the Data in. The sketch compiles but when it runs all ten leds light up, when it should light the leds in the same order as the 1's and 0's in the variable "value", which would be 1111001001. The serial monitor shows the correct ten bits, and all the leds go out for 1.5 seconds and then all the leds light up. Any help is greatly appreciated,
Rich


//LED Strip test single digit

#include <FastLED.h>
#define ledPin 5
#define numLedsPerDigit 10
#define numLeds 10 //total number of leds in strip
CRGB leds[numLeds];


uint16_t value = 0b0000001111001001;

void setup() {
  Serial.begin(9600);
  FastLED.addLeds<WS2812B, ledPin, GRB>(leds, numLeds);
  FastLED.clear();
  FastLED.show();
  delay(1500);
}

void loop() {

  for (int i = 0; i < numLedsPerDigit; i++) {
    bitRead(value, i);
    leds[i] = CRGB(20, 0, 0);
  }

  Serial.println(value, BIN);
  FastLED.show();
  delay(300);
}



You write the color every time without regard to the bit you read, and ignored the value returned.

Try

    if (bitRead(value, i) {
      leds[i] = CRGB(20, 0, 0);
    }

If you get around to changing vakue, you'd have to set the pixels to black before trying to display another time, or put else on the if and do it in the same loop.

a7

1 Like

Yes! It worked perfectly,
Thank you

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