Fastled + WS2812B only ONE lights

Hya,

i have the following code, using fastled lib, but only ONE led lights.

`#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
FASTLED_USING_NAMESPACE

#define DATA_PIN            6
#define NUM_LEDS            4
#define MAX_POWER_MILLIAMPS 500
#define LED_TYPE            WS2812B
#define COLOR_ORDER         GRB

//////////////////////////////////////////////////////////////////////////

CRGB leds[NUM_LEDS];

void setup() {
  delay( 3000); // 3 second delay for boot recovery, and a moment of silence
   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
   FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
}

void loop()
{ 
  
  leds[0] = CRGB::White;
  FastLED.show();


}`

As far i know, FastLED.show(); shall make all lights following the first one, or am i wrong?

Thx in advance for supoort.

You only turn the first LED to white. The show function output whatever is in the leds array to the strip. The LEDs default to off (Black) so you are only setting the first (leds[0]) to White.

This will turn the first led (leds[0]) off and the rest on White.

#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
FASTLED_USING_NAMESPACE

#define DATA_PIN            4
#define NUM_LEDS            4
#define MAX_POWER_MILLIAMPS 500
#define LED_TYPE            WS2812B
#define COLOR_ORDER         GRB

//////////////////////////////////////////////////////////////////////////

CRGB leds[NUM_LEDS];

void setup() {
  delay( 3000); // 3 second delay for boot recovery, and a moment of silence
   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
   FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
}

void loop()
{   
  leds[0] = CRGB::Black;
  for(int n = 1; n < NUM_LEDS; n++)
  {
   leds[n] = CRGB::White;
  }
  FastLED.show();
}
1 Like

OP, Tell use what you think this does:

leds[0] = CRGB::White;

thank you. solved.

for having all,

for(int n = 1; n < NUM_LEDS; n++) 

shall read

for(int n = 0; n < NUM_LEDS; n++).

other way is with

fill_solid(leds, NUM_LEDS, CRGB::White);

thank you for the kind reply.

1 Like

And you understand the relationship of one array element for each pixel.

When you think about it, that can't be correct. The idea of ws2812b is that you can set each led in the strip to a different colour. If that .show() function always made every led the same colour as the first, why not buy the cheaper non-addressable strips, where all the LEDs are always the same colour?

Did you know that you can online test FastLED code ? Scroll halfway this page: https://www.soulmatelights.com/ Type your code, and you see the result immediately. Or click the "Next example" button until you get to the examples that are more fun.

The Wokwi simulator has many FastLED examples: https://wokwi.com/arduino/libraries/FastLED.

1 Like

yes, i know i was wrong. @groundFungus was very nice to explain it and point the solution, instead of saying i'm wrong.

Even experts get things wrong! And not just sometimes, a lot. So don't worry. And apologies if I came over as condescending, old habits die hard. All I was saying is that with a little logical thinking, you didn't need an expert to tell you it was wrong.

ok, no problem... maybe i got it wrong. but thank you so much for helping out this newbie :wink:

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