How to turn on Only one Color in Addressable LED using FastLED library?

I have an addressable LED strip. I want to turn on green Color onl to all over the strip.
I tried the following piece of code. HOwever, the result is not as desired.


#define NUM_LEDS  200
#define LED_PIN   2

CRGB leds[NUM_LEDS];

void setup() 
{  
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() 
{ 
Serial.begin(9600);

   Serial.println("Arduino for loop");
   for (int i=0; i<NUM_LEDS  ; i++)
   {
   leds[i] = CRGB::Green;
  FastLED.show();
  FastLED.setBrightness(100);
  delay(10);
   }

The pictures show the LED used, result obtained and the specifications


is in the picture below.

How do you power your strip?

That is wrong; indices go from 0 to 199, not 200. Better to use

for (int i=0; i<NUM_LEDS; i++)

I used for (int i=0; i<NUM_LEDS; i++),
the result was same, so I used 200. I had used <200. HIt's typing mistake in the question.

there is a fill function in fastled.
No need for a for loop

#include "FastLED.h"  

constexpr uint16_t numLeds {200};
constexpr uint16_t ledPin {8};     // you are on another pin ... change that to what ever is needed

CRGB leds[numLeds];

void setup()
{
  FastLED.addLeds<WS2812B, ledPin, GRB>(leds, numLeds);

  fill_solid(leds, numLeds, CRGB::Green);
  FastLED.show();
}
void loop()
{
  //Serial.begin(9600);
  //  Serial.println("Arduino for loop");

}

void variantWithForNotNecessary()
{
  for (uint16_t i = 0; i < numLeds  ; i++)
  {
    leds[i] = CRGB::Green;
    FastLED.show();
    FastLED.setBrightness(100);
    delay(10);
  }
}
1 Like

@blackone
According to the picture it seems that you have RGBW strip rather than RGB.

This fully explains why you get three different colors on every three diodes.

Added after few minutes:
...Although no .... then there would be white diodes ...

2 Likes

You did not answer the question how you power your strips.

@b707 You are right, it is not a normal ledstrip. The sketch should turn the ledstrip green, see the test Wokwi.

I have given power both from power source snd arduino. When I do leds[0] = CRGB::Green;, the first led is turned green color. But I need the whole strip to be of green color.

This is the picture of the LED

This is the result of the code. It is still not as I expected. There are different colors on each leds.

This code also did not give the desired result. The color of the first led is slightly gree, that of second is blue and the third is red, and repeat.

Which power source? E.g. a cellphone charger will not be enough for 200 leds. To do 200 leds in only green, you need 200 x 20 mA equals 4A; add some overhead and make it 5A. If you want them all white at the same time, you will need 3 times that.

Did you update your first post with pictures ? Or did I miss the "RGBW" on the label ?
afbeelding

If you update your first post, then the flow of the discussion gets disturbed.

You can not use the FastLED in RGB mode to control RGBW leds. You need a signal for the SK6812 RGBW.
I'm afraid that Wokwi has no simulated RGBW ledstrip, but I have a project with the SK6812 RGBW.

FastLED has RGBW support on top of the list since many years, but it is not yet implemented: RGBW Support · Issue #1068 · FastLED/FastLED · GitHub

[UPDATE] I found my project, I used this workaround: https://www.partsnotincluded.com/fastled-rgbw-neopixels-sk6812/
It works very well.

1 Like

I have been using adapter (output 5V 2A). I will follow your instructions.

I updated the post with new picture. I am sorry for not stating this before.

You can do a test with Adafruit's Neopixel Library, But as RGBW.

Adafruit writes:

We have a tutorial showing wiring, power usage calculations, example code for usage, etc. for NeoPixel Please check it out! Please note you will need a NeoPixel library with RGBW support which is not always available. If you try to control these with a plain 'RGB' NeoPixel library, you'll get very weird results. Our Adafruit NeoPixel library does support RGBW but if you're using something else, just be aware that it might require some hacking. Also, the Blue LED element is close to the white phosphor and the light bleeds into it, so blue light will have a mix of white as well.

It helped me. Thank You.

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