FastLED switch LEDs

I'm making something for the holidays and am using WS2811 LEDs and an Arduino. I'm using the FastLED library and I want it that the LEDs display colors, pause, and then have those same LEDs display a new color. Here is my code:

#include <FastLED.h>
#define LED_PIN 13
#define LED_COUNT 10

CRGB leds[LED_COUNT];

void setup() {
  FastLED.addLeds<WS2811, LED_PIN>(leds, LED_COUNT);
}
void loop() {
 /*
 (255,0,0) = Red
 (0,255,0) = Green
 (0,0,255) = Blue
 */
 
  leds[0] = CRGB(255,255,255);
  leds[1] = CRGB(255,255,255);
  leds[2] = CRGB(255,255,255);
  leds[3] = CRGB(255,255,255);
  leds[4] = CRGB(255,255,255);
  leds[5] = CRGB(255,255,255);
  leds[6] = CRGB(255,255,255);
  leds[7] = CRGB(255,255,255);
  leds[8] = CRGB(255,255,255);
  leds[9] = CRGB(255,255,255);
delay(100);
  leds[0] = CRGB(0,0,255);
  leds[1] = CRGB(0,0,255);
  leds[2] = CRGB(0,0,255);
  leds[3] = CRGB(0,0,255);
  leds[4] = CRGB(0,0,255);
  leds[5] = CRGB(0,0,255);
  leds[6] = CRGB(0,0,255);
  leds[7] = CRGB(0,0,255);
  leds[8] = CRGB(0,0,255);
  leds[9] = CRGB(0,0,255);
FastLED.show();
}

My code is very basic because I'm just trying to get it to work before making more logical for loops. Does anyone know how to switch the colors of the LEDs?

You need to issue a FastLED.show(); function each time that you send new data to the LED strip.

If all the pixels (LEDs) in the strip are the same color, use a for loop to change the colors.

Try this (untested):

#include <FastLED.h>
#define LED_PIN 13
#define LED_COUNT 10

CRGB leds[LED_COUNT];

void setup()
{
   FastLED.addLeds<WS2811, LED_PIN>(leds, LED_COUNT);
}
void loop()
{
   /*
      (255,0,0) = Red
      (0,255,0) = Green
      (0,0,255) = Blue
   */
   for (byte n = 0; n < LED_COUNT; n++)
   {
      leds[n] = CRGB(255, 255, 255);
   }
   FastLED.show();

   delay(1000);  // lengthened the delay so the change will better show

   for (byte n = 0; n < LED_COUNT; n++)
   {
      leds[n] = CRGB(0, 0, 255);
   }
   FastLED.show();
}

That's what I thought to but it didn't work. Just tried yours as well and also didn't work, the lights turned white and remained white, didn't switch colors once.

Sorry, I forgot to add a delay after the second color change so that it will show up.

Try this:

#include <FastLED.h>
#define LED_PIN 13
#define LED_COUNT 10

CRGB leds[LED_COUNT];

void setup()
{
   FastLED.addLeds<WS2811, LED_PIN>(leds, LED_COUNT);
}
void loop()
{
   /*
      (255,0,0) = Red
      (0,255,0) = Green
      (0,0,255) = Blue
   */
   for (byte n = 0; n < LED_COUNT; n++)
   {
      leds[n] = CRGB(255, 255, 255);
   }
   FastLED.show();

   delay(1000);  // lengthened the delay so the change will better show

   for (byte n = 0; n < LED_COUNT; n++)
   {
      leds[n] = CRGB(0, 0, 255);
   }
   FastLED.show();

   delay(1000);  // ***************** added delay 
}

Now this code works with my WS2812 strip (real hardware).

Does it work now?

it does. thank you so much!

Glad to help. :slight_smile:

If your question has been answered to your satisfaction, please mark the thread as solved so that other members that wish to help will not waste their time opening and reading the thread only to find that you no longer require assistance.

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