Need help with a sketch to chase LEDs

I have an Arduino Uno and a string of 36 LEDs. What I am trying to do is have a set of 3 LEDs chase the string with 9 LEDs spacing between each set of 3 in a loop. I am using NeoPixel RGBs so I would like to also control what color is displayed. Can this be done with a sketch or will I need additional hardware?

You could certainly code that into a sketch. No additional hardware needed for any particular pattern, but make sure you use a suitable power supply, perhaps 2.5A @ 5V. Its too much for an Arduino to supply via its regulator, but an external supply like that could run both the Arduino and the led strip.

If you will only ever have 9 out of the 36 leds on, the Arduino's regulator can cope with that, but the temptation will be to try other patterns, which could overload it.

Paul

I am running a 3A power supply so that is not an issue. Are you able to help me with the sketch?

cyberpitboss: Are you able to help me with the sketch?

cyberpitboss: I am certain that I do not want to learn this code. I do not have time to do it.

So are you asking me to write the sketch for you or help you write it yourself? If the former, you already know the answer, if the latter, I am perfectly willing to provide as much help as you need, as will others here.

Do you have the "strandtest" sketch running OK for your 36 leds? Use that as the basis. Don't worry about how it all works, we can junk most of it anyway.

You have decided on the 3 on/9 off chasing pattern, but what do you want to do with the colours? Will groups of 3 always be the same colour? Will the colour of each group be contrasting to the last group, or very slightly different, or...?

Paul

Thanks Paul, yes I would like to be able to write the sketch.

I have everything working in the strandtest with 36 lights and I am able to work with the different colors. Pretty much understand everything in the current void loop.

When it comes to the code below the void loop, I am really confused.

I want the groups of colors to allways be the same but would like to tweek them to suit the project. We are trying to edge light a rain pattern in glass so that is why we want the chasing lights.

I want one side of the glass chasing at one rate and the other side at a different rate. I can use 2 Ardrino Unos to do that once I get the lights to chase if that is the easiest way to do it.

Does this answer all of your questions?

I would suggest looking at using the FastLED library for your Neopixel. http://fastled.io/

The LED chasing sketch is called Cylon.

I used it for my WS2812B LED strips and found it easy to use.

So you really want 36 x 2 strips running independant patterns? Perfectly possible with one Arduino.

And you are happy to have the patterns use a fixed colour which you can adjust by changing it in the sketch and re-uploading?

Both strings whould have chasing patterns of 3 on 9 off, but at different rates? These rates would also be fixed but adjusted by changing & re-uploading the sketch?

PaulRB: So you really want 36 x 2 strips running independant patterns? Perfectly possible with one Arduino.

That is great news. Hope I can handle the code.

PaulRB: And you are happy to have the patterns use a fixed colour which you can adjust by changing it in the sketch and re-uploading?

Yes that would be perfect for this project.

PaulRB: Both strings whould have chasing patterns of 3 on 9 off, but at different rates? These rates would also be fixed but adjusted by changing & re-uploading the sketch?

Yes that is what we want to do. They can run the same pattern but not synchronized. Trying to simulate rain.

On another project we would like to use the same chase but have the colors go from red to orange to yellow as they chase from one end to the other. But I do not know if I am knowledgeable enough for that one.

ieee488: I would suggest looking at using the FastLED library for your Neopixel. http://fastled.io/

The LED chasing sketch is called Cylon.

I used it for my WS2812B LED strips and found it easy to use.

Thanks, I installed the library and called up the Cylon sketch but it does not want to compile. It gets about 2/3 the way through and does not go any further. How long should it take to compile? I think that I may have to modify the void loop in some fashion but I am too new to know what to modify.

cyberpitboss:
Thanks, I installed the library and called up the Cylon sketch but it does not want to compile. It gets about 2/3 the way through and does not go any further. How long should it take to compile? I think that I may have to modify the void loop in some fashion but I am too new to know what to modify.

I think there may be an error with the setup() function for the Cylon sketch.

Try FastLED.addLeds<NEOPIXEL, DATA_PIN, RGB>(leds, NUM_LEDS); in setup().

Also try, the testleds sketch.

ieee488:
I think there may be an error with the setup() function for the Cylon sketch.

Try FastLED.addLeds<NEOPIXEL, DATA_PIN, RGB>(leds, NUM_LEDS); in setup().

Also try, the testleds sketch.

That worked for the chase and now I just need to figure out how to make the chase in 3 lite sets with 9 lites dark in between. Right now I am only chasing 1 lite with 35 lites dark in a 36 lite string. Any ideas would be greatly appreciated.

Post the sketch you have now. Don't forget the code tags!

cyberpitboss:
That worked for the chase and now I just need to figure out how to make the chase in 3 lite sets with 9 lites dark in between. Right now I am only chasing 1 lite with 35 lites dark in a 36 lite string. Any ideas would be greatly appreciated.

See if the following works.

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 36

// For led chips like Neopixels; which have a data line; ground; and power; you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data; clock;
// ground; and power); like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

CRGB row1[NUM_LEDS];


void setup() 
{ 
      FastLED.addLeds<NEOPIXEL, DATA_PIN, GRB>(leds, NUM_LEDS);

 
    setColors();
}

void loop() 
{ 
    for (int j = 0; j < NUM_LEDS; j++)
    {
        assignTo(j);
        FastLED.show();
        delay(2000);
    }
}

void assignTo(int j)
{
    int i;


    for (i = 0; i < NUM_LEDS; i++)
    {
        leds[i] = row1[(i + j) % NUM_LEDS];
    }
}    


void setColors()
{
  row1[0] = CRGB::Red;
  row1[1] = CRGB::Red; 
  row1[2] = CRGB::Red;
  row1[3] = CRGB::Black;
  row1[4] = CRGB::Black;
  row1[5] = CRGB::Black;
  row1[6] = CRGB::Black;
  row1[7] = CRGB::Black;
  row1[8] = CRGB::Black;
  row1[9] = CRGB::Black;
  row1[10] = CRGB::Black;
  row1[11] = CRGB::Black;
  row1[12] = CRGB::Red;
  row1[13] = CRGB::Red;
  row1[14] = CRGB::Red;
  row1[15] = CRGB::Black;
  row1[16] = CRGB::Black;
  row1[17] = CRGB::Black;
  row1[18] = CRGB::Black;
  row1[19] = CRGB::Black;
  row1[20] = CRGB::Black;
  row1[21] = CRGB::Black;
  row1[22] = CRGB::Black;  
  row1[23] = CRGB::Black;
  row1[24] = CRGB::Red;
  row1[25] = CRGB::Red;
  row1[26] = CRGB::Red;
  row1[27] = CRGB::Black;
  row1[28] = CRGB::Black;
  row1[29] = CRGB::Black;  
  row1[30] = CRGB::Black;
  row1[31] = CRGB::Black;
  row1[32] = CRGB::Black;
  row1[33] = CRGB::Black;
  row1[34] = CRGB::Black;
  row1[35] = CRGB::Black;
}

ieee488:
See if the following works.

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 36

// For led chips like Neopixels; which have a data line; ground; and power; you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data; clock;
// ground; and power); like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

CRGB row1[NUM_LEDS];

void setup()
{
     FastLED.addLeds<NEOPIXEL, DATA_PIN, GRB>(leds, NUM_LEDS);

setColors();
}

void loop()
{
   for (int j = 0; j < NUM_LEDS; j++)
   {
       assignTo(j);
       FastLED.show();
       delay(2000);
   }
}

void assignTo(int j)
{
   int i;

for (i = 0; i < NUM_LEDS; i++)
   {
       leds[i] = row1[(i + j) % NUM_LEDS];
   }
}

void setColors()
{
 row1[0] = CRGB::Red;
 row1[1] = CRGB::Red;
 row1[2] = CRGB::Red;
 row1[3] = CRGB::Black;
 row1[4] = CRGB::Black;
 row1[5] = CRGB::Black;
 row1[6] = CRGB::Black;
 row1[7] = CRGB::Black;
 row1[8] = CRGB::Black;
 row1[9] = CRGB::Black;
 row1[10] = CRGB::Black;
 row1[11] = CRGB::Black;
 row1[12] = CRGB::Red;
 row1[13] = CRGB::Red;
 row1[14] = CRGB::Red;
 row1[15] = CRGB::Black;
 row1[16] = CRGB::Black;
 row1[17] = CRGB::Black;
 row1[18] = CRGB::Black;
 row1[19] = CRGB::Black;
 row1[20] = CRGB::Black;
 row1[21] = CRGB::Black;
 row1[22] = CRGB::Black;  
 row1[23] = CRGB::Black;
 row1[24] = CRGB::Red;
 row1[25] = CRGB::Red;
 row1[26] = CRGB::Red;
 row1[27] = CRGB::Black;
 row1[28] = CRGB::Black;
 row1[29] = CRGB::Black;  
 row1[30] = CRGB::Black;
 row1[31] = CRGB::Black;
 row1[32] = CRGB::Black;
 row1[33] = CRGB::Black;
 row1[34] = CRGB::Black;
 row1[35] = CRGB::Black;
}

It looked like it would work fine however it fails to complile. It never progresses more than 25% and then never finishes and no errors to report. I am sure it is just something simple but I have not been able figure out a way to make it work with any of my own tweaks.

PaulRB:
You could certainly code that into a sketch. No additional hardware needed for any particular pattern, but make sure you use a suitable power supply, perhaps 2.5A @ 5V. Its too much for an Arduino to supply via its regulator, but an external supply like that could run both the Arduino and the led strip.

If you will only ever have 9 out of the 36 leds on, the Arduino’s regulator can cope with that, but the temptation will be to try other patterns, which could overload it.

Paul

I have a 3A power supply so that is not a problem. If you can help me find the problem with this code I would be very grateful. It looks like it should work but it fails to compile. It hangs at about 25% and that is as far as it goes. Here is what I have so far:

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 36

// For led chips like Neopixels; which have a data line; ground; and power; you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data; clock;
// ground; and power); like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

CRGB row1[NUM_LEDS];


void setup()
{
      FastLED.addLeds<NEOPIXEL, DATA_PIN, GRB>(leds, NUM_LEDS);

 
    setColors();
}

void loop()
{
    for (int j = 0; j < NUM_LEDS; j++)
    {
        assignTo(j);
        FastLED.show();
        delay(2000);
    }
}

void assignTo(int j)
{
    int i;


    for (i = 0; i < NUM_LEDS; i++)
    {
        leds[i] = row1[(i + j) % NUM_LEDS];
    }
}    


void setColors()
{
  row1[0] = CRGB::Red;
  row1[1] = CRGB::Red;
  row1[2] = CRGB::Red;
  row1[3] = CRGB::Black;
  row1[4] = CRGB::Black;
  row1[5] = CRGB::Black;
  row1[6] = CRGB::Black;
  row1[7] = CRGB::Black;
  row1[8] = CRGB::Black;
  row1[9] = CRGB::Black;
  row1[10] = CRGB::Black;
  row1[11] = CRGB::Black;
  row1[12] = CRGB::Red;
  row1[13] = CRGB::Red;
  row1[14] = CRGB::Red;
  row1[15] = CRGB::Black;
  row1[16] = CRGB::Black;
  row1[17] = CRGB::Black;
  row1[18] = CRGB::Black;
  row1[19] = CRGB::Black;
  row1[20] = CRGB::Black;
  row1[21] = CRGB::Black;
  row1[22] = CRGB::Black;  
  row1[23] = CRGB::Black;
  row1[24] = CRGB::Red;
  row1[25] = CRGB::Red;
  row1[26] = CRGB::Red;
  row1[27] = CRGB::Black;
  row1[28] = CRGB::Black;
  row1[29] = CRGB::Black;  
  row1[30] = CRGB::Black;
  row1[31] = CRGB::Black;
  row1[32] = CRGB::Black;
  row1[33] = CRGB::Black;
  row1[34] = CRGB::Black;
  row1[35] = CRGB::Black;
}

I got a page of error messages when I compiled your sketch. I used Arduino IDE 1.0.5 and FastLED 3.0.1.

When I changed the following line as shown:

     FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

it then compiled in 10~15 secs with no errors or warnings.

Same result on IDE 1.6.1.

Paul

PaulRB:
I got a page of error messages when I compiled your sketch. I used Arduino IDE 1.0.5 and FastLED 3.0.1.

When I changed the following line as shown:

     FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

it then compiled in 10~15 secs with no errors or warnings.

Same result on IDE 1.6.1.

Paul

Well thanks Paul. That was a great accomplishment. I only had one error in that I did not have DATA_PIN defined but now it is working great. Is there an easy way to make the chase go in the opposite direction?

I finally figured it out changing this line:

 for (int j = NUM_LEDS-1; j >= 0; j--)