LED strip address mapping?

Hi,

I have a standard WS2812B LED strip. When I color the first LED (index 0) it works fine. When I color the second LED (index 1) with a white color and the first and second LED light up (the second has a greenish color). When I light the third LED (index 2) the second and third light up. When I color the fourth (index 3), it lights up the third LED only.

It's like the array index it being divided by a factor like 1.33. Any ideas why this would happen? Here's the super simple code:

#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 144
#define BRIGHTNESS 20
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int startIndex;
void setup() {
delay(100); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
for (int i=0;i<NUM_LEDS;i++) {
leds*=0;*

Please explain better. What does that code do? What's the point of that for loop that seems pointless? Why is shit italicized?

Haha. I have no idea why that got italicized. The point of the code is simply to light one LED only and keep it that way. But it lights two.

This will happen down the line of my entire 144 light strip. When I set leds[143] to light up, an LED that's about 3/4 down the strip lights up. It's like my array index is being divided my a factor.

Hopefully this video will explain better then I can. It's should just light one LED every second down the strip. Here's the new code:

#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 144
#define BRIGHTNESS 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int startIndex;
void setup() {
startIndex=0;
delay(100); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
for (int i=0;i<NUM_LEDS;i++) {
leds*=0;*

  • }*
  • FastLED.show();*
    }
    void loop() {
  • for (int i=0;i<NUM_LEDS;i++) {*
    _ leds*=0;_
    _
    }_
    _
    leds[startIndex % 20]=12508340;_
    _
    delay(1000);_
    _
    startIndex=startIndex+1;_
    _
    FastLED.show();_
    _
    }*_

Darn. First video was too big. Here's a smaller one with slightly modified code (only 10 ligths instead of 20)...

#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 144
#define BRIGHTNESS 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int startIndex;
void setup() {
startIndex=0;
delay(100); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
for (int i=0;i<NUM_LEDS;i++) {
leds*=0;*

  • }*
  • FastLED.show();*
    }
    void loop() {
  • for (int i=0;i<NUM_LEDS;i++) {*
    _ leds*=0;_
    _
    }_
    _
    leds[startIndex % 10]=12508340;_
    _
    delay(1000);_
    _
    startIndex=startIndex+1;_
    _
    FastLED.show();_
    _
    }*_

Look at this line of code you posted:

leds=0;

Is that the same as you remember it in the Arduino IDE? Could there be a connection between that line and the italicized code?

I have no idea why that got italicized.

That is because you failed to read the how to use this forum sticky post. And if you can’t be bothered to read it, why should folk be bothered to help you.

for (int i=0;i<NUM_LEDS;i++) {
   leds=0;
  }

Does absolutely nothing. Learn how to use an array, and stop posting the same rubbish over and over.

leds=0;
leds=0;
leds=0;
leds=0;
.
.
.
.
144 times

I also googled '12508340' and learned about hereditary pancreatitis.

What was the question again?

Wouldn't assigning 0 to leds screw everything up?

It's an array, you should be using the array index, or the FastLED wrapper for setting pixel color (if they have one).

Apologies for being new to this. I looked and couldn't find "how to use this forum sticky post". Please send me a link to that. When I copy & paste my code, the code get altered (square brackets sometimes disappear and text sometimes gets italicized). I also can't figure out how to pre-view my post so I can't check it before it's already posted. Sorry for wasting anyone's time.

I am setting the leds array element 1 to an arbitrary white light value of 12508340 (there is no connection between that number and Hereditary pancreatitis). So, one would think a single LED on a strip of 144 LEDs would light up. However two adjacent LEDs are lighting up. This only happens on certain LED strips that say they are WS2812B compatible. Other LED strips I've used in the past that are also WS2812B work fine.

USE CODE TAGS FOR CODE

It's the button that looks like </> next to B I U

am setting the leds array element 1 to an arbitrary white light value of 12508340 (there is no connection between that number and Hereditary pancreatitis). So, one would think a single LED on a strip of 144 LEDs would light up.

No you would not expect only one light to light up.

That is a big number and takes more than the 24 bits allotted for one array element. That is why it spills over into the next array element and you see two LEDs lit up.

Use proper sensible numbers and it will not happen.

rtfmkthx

Thank you all for your help! I've read through the FastLED Basic-usage and simplified my code. Here's what happens after every loop (each second):

1st: LED 0 is red
2nd: LED 1 is green
3rd: LED 1 is white
4th: LED 2 is blue
5th: LED 3 is red
6th: LED 4 is green
7th: LED 4 is white
8th: LED 5 is blue
9th: LED 6 is red
10th: LED 7 is green

Then it repeats. Here's the code...

#include <FastLED.h>
#define LED_PIN     5
#define NUM_LEDS    144
#define BRIGHTNESS  2
#define LED_TYPE    NEOPIXEL
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int startIndex;
void setup() {
  startIndex=0;
  delay(100);
  FastLED.addLeds<LED_TYPE, LED_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  for (int i=0;i<NUM_LEDS;i++) {
   leds[i]=0;
  }
  FastLED.show();
}
void loop() {
  leds[startIndex % 10]=CRGB::Red;
  FastLED.show();
  delay(1000);
  leds[startIndex % 10]=CRGB::Black;
  startIndex=startIndex+1;
}

I can probably figure out somewhere to post a video if need be.

I have run the code you posted in the last post. I can report that it behaves exactly like you would expect. That is the first 10 LEDs display as red with only one red LED on at any one time with all the other LEDs off.
No other colour is displayed, only one LED is on at one time, and only the first 10 LEDs in the strip are lit in the sequence.

So either your code does not match your processor, I used a Uno, or your strip does not match what you declared it to be in the code, or your strip is broken. Although I suppose some other hardware fault is possible.