FastLED Chase Sequence with Multiple Colors (3) WS2812 LED Strip

Hello everyone and thank you for reading my post

I am new to arduino, thought i have done some programming in the past.
I have done a great deal through the years with Motorola/Free scale micro controllers using assembly language

I have been toying with the FASTLED library and i have found it to be pretty awesome so far. but i have hit a road block and i was hoping to get some direction.

What i am looking to do is, take a strip of 50 LEDS. i want to make the LEDs 3 colors: Red, Green, and White. I would like to have these colors chase eachother on the strip of LEDS.

i have come up with one way to do it, however it is not very elegant. (See the attached file (R_W_G_1-5-2020) it takes alot of memory, and doesn’t make it easy to modify or change anything

I have also been experimenting with some of the “theater chase” programs i have found. I have attached one here. (Chase_Lights_Single_Color) This seems like a much more elegant solution which requires less memory. I was hoping someone could give me a tip or two on how to add more colors to the chase lights sketch, or a whole new way to look at this possible.

I am sure there is a way to use the chase lights sketch but i cannot figure it out.

Thank you all for your time and input

R_W_G_1-5-2020.ino (4.97 KB)

Chase_Lighs_Single_Color.ino (636 Bytes)

One thing at a time.
(I started programming in assembler on 6502 and 8080 processors).

On your “crude” sketch, I rewrote it to use a loop to set the LEDs:

#include "FastLED.h"
#define NUM_LEDS 50
#define DATA_PIN 3
#define BRIGHTNESS 12
#define NUM_COLORS 3

CRGB leds[NUM_LEDS];
int j = 0;        // Starting color number
CRGB myColors[] = {CRGB::Red, CRGB::White, CRGB::Green};

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness( BRIGHTNESS );
  FastLED.clear ();
}

void loop() {
  for (int i = 0; i <= NUM_LEDS; i++) {
    leds[i] = myColors[(i + j) % NUM_COLORS];  // mod restricts the color number
  }
  FastLED.show();

  j = (j + 1) % NUM_COLORS;                // Cycle through the starting LED#
  delay(500);
}

This cycles through the three LED colors like your sketch, plus you can easily add more colors.

The chase lights sketch works here. What isn’t working for you?

By the way, there is an error in your sketch. You defined an array of 50 LEDs, but you address 51 in the code. Real programmers count from zero.

1 Like

SteveMann

Thank you for getting back to me.
thank you for busting my balls about starting at 0. lol.
i go back and forth with that all the time. In my professional life i deal with CAN communications and yes real programmers start at 0. but the Society of Automotive Engineers starts at 1. This leads to all sorts of confusion with software, in the field and obviously it spills into my personal projects at times.

The Chase Light Sketch worked for me, i was having an issue getting more than 1 color to show up though.

I will give this a shot today when i get home from work.

I have used the 6811 and i still use the 6812. i use it regularly for personal projects. However when using these LEDs, i figured i would give the arduino a try since there was already code written to use the addressable LEDS. it saved me a ton of time bit banging with my Motorola gear.

Again, Thank you for your help.

Bit banging is how I used to work- trying to fit a control program into a 2Kb EPROM. When management wanted to add a new feature, it was a weeks-long battle to convince them that it just would not fit into a 2K EPROM. Changing the hardware to a 4K EPROM was not simple and the hardware designers argued that I should try harder to make the code fit into 2K. Finally agreeing to changing the hardware then made Marketing unhappy because this would increase the product price more than the new feature was worth. Those were the days…

I did not try to unravel the Chase Light sketch.

You know you are a real programmer when you dream in code. And I did think of a new approach to your chase-light question in a lucid dream. I changed the code so that the number of colors is dynamic. All you have to do is put whatever colors you want into the myColors array. To make a marquee, just put a few black colors into the array. (Note, I am using a different board and different LEDs, but the code is basically the same).

I don’t know why the marquee effect runs backwards. Let me know if you get it to run forward.

/*
   Demo of theatre marquee-style chase LEDs
*/

#include "FastLED.h"
#define NUM_LEDS 50
#define DATA_PIN D2
#define BRIGHTNESS 50

CRGB leds[NUM_LEDS];
CRGB myColors[] = {CRGB::Red, CRGB::Green, CRGB::Blue, CRGB::Black, CRGB::Black};
int j = 0;        // Starting color number
byte numColors;   // Will contain the number of colors in the myColors array.

void setup() {
  Serial.begin(115200);
  Serial.println();

  numColors = (sizeof(myColors) / sizeof(myColors[0]));
  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  FastLED.setBrightness( BRIGHTNESS );
  FastLED.clear ();
}

void loop() {
  for (int i = 0; i <= NUM_LEDS; i++) {
    leds[i] = myColors[(i + j) % numColors];    // mod 3 means the color number will be 0-2.
  }
  FastLED.show();

  j = (j + 1) % numColors;        // Cycle through the starting LED#, 0 to numcolors-1
  delay(200);
}

The days when 2K of anything mattered, am i right?
and gotta love the marketing folks… All the stuff they promise and never deliver.
when i did alot of assembly programing i would always unravel my most difficult problems right before i went to sleep. i used to keep a notepad by my bed so i could write things down.

I ran both the codes. I had better luck with the first one. It looked pretty great on my setup. i am working on making some adjustments but i am slow with this as i am still in the early stages of learning some of this stuff.

The second program ran really strange for me. the first 3 LEDs lit up the correct color, then the rest of the string kept incramenting through strange shades of blue and white. i also am getting a strange error when i compile the program. It compiles and loads however i am trying to figure out why my development environment is giving the error. But i am going to keep at it. Thank you for the leg up this is going to get me to where i need to be. your time is much appreciated.

SmallBrownBike:
The second program ran really strange for me. the first 3 LEDs lit up the correct color, then the rest of the string kept incramenting through strange shades of blue and white. i also am getting a strange error when i compile the program. It compiles and loads however i am trying to figure out why my development environment is giving the error. But i am going to keep at it. Thank you for the leg up this is going to get me to where i need to be. your time is much appreciated.

Did you change the LED type and color order? My setup is using WS2811 and they are RGB. I believe that you are using WS2812B and GRB.