code for neopixel strip

Can anyone help me to light led neo strip like this.
using one input,five neo strip connects each one after another.
hope 2D array method will but dont know how to start.

look into FastLED library or Neopixel library

Before we can go further we need to know if the matrix is connected in a liner way or a serpentine way.

Linear is where the first column has LEDs numbed 0 to 4, going from bottom to top and the second has LEDs numbed 5 to 9 going up.

A serpentine raster is where the first column has LEDs numbed 0 to 4, going from bottom to top and second has LEDs numbed 5 to 9 but going down.

ieee488: look into FastLED library or Neopixel library

Grumpy_Mike:
Before we can go further we need to know if the matrix is connected in a liner way or a serpentine way.

Linear is where the first column has LEDs numbed 0 to 4, going from bottom to top and the second has LEDs numbed 5 to 9 going up.

A serpentine raster is where the first column has LEDs numbed 0 to 4, going from bottom to top and second has LEDs numbed 5 to 9 but going down.

Actually i have no idea about liner way or a serpentine way.
I will attach a diagram how i connect the neo strips.

this is the effect that i need

I will attach a diagram how i connect the neo strips.

OK so that is a serpentine raster, so called because it looks like a snake.

Now number the LEDs 0 to 24 like this.

Now write down what LEDs need to be on for each step of your display.
Then write a series of function calls that set those number LEDs to the colours you want. After each set perform the strip.show method, have a small delay, wipe the buffer clean and then repeat for the next step in the pattern.

I know this is tedious and long winded but it is the simplest way of going about it for such a simple pattern.

I can’t see much similarity to the pattern you posted first and the picture. Are you sure what you photographed was a Neopixel strip?

Grumpy_Mike:
OK so that is a serpentine raster, so called because it looks like a snake.

Now number the LEDs 0 to 24 like this.

Now write down what LEDs need to be on for each step of your display.
Then write a series of function calls that set those number LEDs to the colours you want. After each set perform the strip.show method, have a small delay, wipe the buffer clean and then repeat for the next step in the pattern.

I know this is tedious and long winded but it is the simplest way of going about it for such a simple pattern.

I can’t see much similarity to the pattern you posted first and the picture. Are you sure what you photographed was a Neopixel strip?

I just write a code to neo strip, same strip i mention in above.
its light rainbow colors forward and revers,but when colors reversing “0” pixel stay off.waht is the problem you think? pls help

``````void rainbowR(uint8_t wait)
{
for (int n=0; n<5; n++)
{
uint16_t i, j;
for(j=256; j>0; j--)
{
for(i=strip.numPixels(); i>0; i--) //have a problem in pixel "0" is not light up.
{
strip.setPixelColor(ledArray6[i], Wheel((i+j) & 255));
}
strip.show();
delay(5);
}
}
}
``````
``````for(i=strip.numPixels(); i>0; i--) //have a problem in pixel "0" is not light up.
``````

Because the loop only runs while i is greater than 0, therefore when i is equal to 0 it stops and does not turn the LED on. Use:-

``````for(i=strip.numPixels(); i>=0; i--) //have no problem in pixel "0" it will light up.
``````

I try it,but its not working after i change the code(its not light up)
below is the full code,I used a Array for this,i dont know if there a problem of my array.

``````#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 149

int ledArray6[] =
{
0,  1, 2, 3, 4,
148, 147, 146, 145,
9, 8, 7, 6, 5,
141, 142, 143, 144,
10,  11,  12,  13,  14,
140, 139, 138, 137,
15,  16,  17,  18,  19,
133, 134, 135, 136,
24,  23,  22,  21,  20,
132, 131, 130, 129,
25,  26,  27,  28,  29,
125, 126, 127, 128,
34,  33,  32,  31,  30,
124, 123, 122, 121,
35,  36,  37,  38,  39,
117, 118, 119, 120,
44,  43,  42,  41,  40,
116, 115, 114, 113 ,
45,  46,  47,  48,  49,
109, 110, 111, 112,
54,  53,  52,  51,  50,
108, 107, 106, 105,
55,  56,  57,  58,  59,
101, 102, 103, 104,
64,  63,  62,  61,  60,
100, 99, 98,  97,
65,  66,  67,  68,  69,
96,  95,  94,  93,
74,  73,  72,  71,  70,
89,  90,  91,  92,
75,  76,  77,  78,  79,
88,  87,  86,  85,
84, 83,  82,  81,  80,
};

void setup()
{
strip.begin();
strip.setBrightness(20);
strip.show();

}

void loop()
{

//rainbow(10);
rainbowR(10);

}

//-------------------------rainbow---------------------------------------------------
void rainbow(uint8_t wait)
{
for (int n=0; n<5; n++)
{
uint16_t i, j;

for(j=0; j<256; j++)
{
for(i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(ledArray6[i], Wheel((i+j) & 255));
}
strip.show();
delay(5);
}
}
}
//-------------------------rainbow revers---------------------------------------------------
void rainbowR(uint8_t wait)
{
for (int n=0; n<5; n++)
{
uint16_t i, j;
for(j=256; j>0; j--)
{
for(i=strip.numPixels(); i>=0; i--)  //now the Strip is OFF (0,0,0)
{
strip.setPixelColor(ledArray6[i], Wheel((i+j) & 255));
}
strip.show();
delay(5);
}
}
}
//----------------------------------------------------------------------------------------
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
``````

I try it,but its not working after i change the code(its not light up)

What exactly does that mean? Is it that there is nothing lighting up or is it that the LED 0 is not doing what you expect? Please say what you expect to see.

Grumpy_Mike: What exactly does that mean? Is it that there is nothing lighting up or is it that the LED 0 is not doing what you expect? Please say what you expect to see.

Thanks for reply mike, I mean there is nothing lighting up.all leds are black.

So let's get this straight. You have a function in the code called rainbow which you never call because it is commented out. But when you call it then you get the LEDs lit and fading. However when you call the function rainbowR you don't get any LEDs lit. Is that what you are seeing?

Grumpy_Mike:
So let’s get this straight. You have a function in the code called rainbow which you never call because it is commented out. But when you call it then you get the LEDs lit and fading. However when you call the function rainbowR you don’t get any LEDs lit. Is that what you are seeing?

wow! Thanks for quick reply mike.
sorry my English is not so good.
yes mike its lit and fading like below.(almost) in “rainbow”
rainbowR working when i use code like this (only “0” pixel not working.)

``````for(i=strip.numPixels(); i>0; i--)
``````

but if i change the code as you say,all leds stop working

``````for(i=strip.numPixels(); i>=0; i--)
``````

That is very odd. Let me try it on my system tonight and I will get back to you.

Grumpy_Mike: That is very odd. Let me try it on my system tonight and I will get back to you.

Thanks Mike your help me a lot.We have no one to ask this kind of thing in sri lanka.I really appreciate your help.

I haven't tried this yet but it came to me while driving back what your problem is. You should use

``````for(i=strip.numPixels()-1; i>=0; i--)
``````

This is because with 149 LEDs the LED numbers run from 0 to 148, so when you start the loop with i at 149 you are going to use numbers outside the bounds of the array. This can result in writing to areas of memory that contain other stuff and can cause failure in strange ways. You also need to do this for the other loop too

``````for(j=255; j>=0; j--)
``````

Sorry for not spotting this sooner.

In addition to that, the other thing you have to change is:-
uint16_t i, j
into
int i, j

The unsigned integer was preventing the backwards counting loop from working because numbers in this form can never be less than zero and you need them to be less than zero to stop the backwards loop, and have the last index of zero processed by the loop.

The full code for that function should read:-

``````void rainbowR(uint8_t wait)
{
for (int n=0; n<5; n++)
{
int i,j;
for(j=255; j>=0; j--)
{
for(i=strip.numPixels()-1; i>=0; i--)  //now the Strip is OFF (0,0,0)
{
strip.setPixelColor(ledArray6[i], Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
}
``````

As a hint for the future to help you do what I did.

I found this by including a print in the for loop of the value of the variable i, then I could see it was not producing the values I expected. That set me looking why and that is how I found the error in the variable type for the loop index.

Grumpy_Mike:
I haven’t tried this yet but it came to me while driving back what your problem is.
You should use

``````for(i=strip.numPixels()-1; i>=0; i--)
``````

This is because with 149 LEDs the LED numbers run from 0 to 148, so when you start the loop with i at 149 you are going to use numbers outside the bounds of the array. This can result in writing to areas of memory that contain other stuff and can cause failure in strange ways.
You also need to do this for the other loop too

``````for(j=255; j>=0; j--)
``````

Sorry for not spotting this sooner.

Grumpy_Mike:
In addition to that, the other thing you have to change is:-
uint16_t i, j
into
int i, j

The unsigned integer was preventing the backwards counting loop from working because numbers in this form can never be less than zero and you need them to be less than zero to stop the backwards loop, and have the last index of zero processed by the loop.

The full code for that function should read:-

``````void rainbowR(uint8_t wait)
``````

{
for (int n=0; n<5; n++)
{
int i,j;
for(j=255; j>=0; j–)
{
for(i=strip.numPixels()-1; i>=0; i–)  //now the Strip is OFF (0,0,0)
{
strip.setPixelColor(ledArray6[i], Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
}

``````

As a hint for the future to help you do what I did.

I found this by including a print in the for loop of the value of the variable i, then I could see it was not producing the values I expected. That set me looking why and that is how I found the error in the variable type for the loop index.
``````

Yes!!! its working!!! thanks you so much sir!! and thanks for the hint too!!