ARDUINO and ws2801 RGB LED strip

Hi all,

I am a beginner in the field of programming and I have to program an adressable RGB-LED strip (ws2801) for one of my assignments.

I have some difficulties in programing this with arduino.

I would really appreciate it if anyone could help me and advice me on this.

here is how I have to program it:

I need a program to turn on all LEDs (32 LEDs) in white color and afterwards turining them off (one by one).

when this (turn-off) reaches to the last 6 LEDs, switch their color into pink and then turn them off.

again, when "turn-off’reaches to the last 2 LEDs, switch thir color into red and then turn them off.

thank you very much!

I know it can take some time of you, but can someone help me pleasssssssssssssse?

I am really stuck :frowning:

What is it you don’t understand ? The data format of the WS2801 ? How to program an Arduino ? You’ve haven’t specified where it is that you’re getting lost.

There were examples on the product page…and there are other examples out on the internet.

Start with that. Learn something.

This is not a free consulting/do-all-your-work-for-you forum.

When the code you write breaks, post it here, and people will probably be more likely to help you.

Thanks mee_n_mac,

I used WS2801 library (https://github.com/adafruit/WS2801-Library) in the following program, however I still don’t know how to change the last 6 LED into red before turning them off. Even I don’t know whether it is possible or not. Can anyone let me know?

#include “SPI.h”

#include “WS2801.h”

int SDI = 2; // Serial gray scale data input

int CKI = 3; // Data clock input

WS2801 strip = WS2801(32, SDI, CKI);

void setup() {

strip.begin();

strip.show();

}

void loop() {

colorAppear (Color(255, 250, 250), 50);

colorAppear (Color(0, 0, 0), 5000);

}

void colorAppear (uint32_t c, uint8_t wait) {

for (int i=0; i < strip.numPixels(); i++) {

strip.setPixelColor(i, c);

strip.show();

delay(wait);

}

}

// Creating a 24 bit color value from R,G,B

uint32_t Color(byte r, byte g, byte b)

{

uint32_t c;

c = r;

c <<= 8;

c |= g;

c <<= 8;

c |= b;

return c;

}

mahban.irandoust:
I used WS2801 library (https://github.com/adafruit/WS2801-Library) in the following program, however I still don’t know how to change the last 6 LED into red before turning them off. Even I don’t know whether it is possible or not. Can anyone let me know?

Fisrt I am going to assume by LED strip you mean this …

http://www.sparkfun.com/products/10312

So to understand what it can or can’t do, you need to figure out what the controller chip, the W2801, can or can’t do … at least in general terms.

http://www.sparkfun.com/datasheets/Comp … WS2801.pdf

The WS2801 takes in 24 bits of data and turns on a triad of red, green and blue LEDs according to that data. The 24 bits is really three 8 bit blocks, a block for red, a block for green and a block for blue. By setting the individual values for R, G and B you can make the triad output nearly any color. Lastly the W2801’s are “daisy chained” so the RGB data sent to the 1’st triad of LEDs gets “pushed” to the last triad of LEDs if you keep sending blocks of data. If you send 32*3 blocks of data you’ll have sent a color setting for all of the LEDs in the strip. Look at the numbers above and see if you can’t correlate them to the code you posted. See anything interesting ?

So with this knowledge you can say “Yes, it’s possible to do the assignment”. Whether you can do it using the just the software/code above is another question. Looking at what you’ve posted for code, I’d say you’re going to have to write some yourself … which is, of course, the purpose of the assignment.

Look at the function Color. When called it takes three bytes of RGB data and packs it into 1 word. So far so good, Look at the function colorAppear. It takes the word from Color and a time and does :

void colorAppear (uint32_t c, uint8_t wait) {
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);

So what do you think the above is doing ? Well it depends on what strip.setPixelColor and strip.show do. These are library functions and you should be able to find a description for them. Looking at how they’re used and their names I can make a good guess though. strip.setPixelColor will set the color of the triad of LEDs determined by the “i” value passed to it. strip.setPixelColor(7, c) will set the 7’th LED triad to color “c”. I’m less sure but will further guess that strip.show then turns on those LEDs. So the present version of colorAppear takes 1 color setting and sends it to each and every set of LEDs and turns them on, with a delay between doing it for each one. This is where you need to write (or rewrite) your new code. Knowing how colorAppear works, you should be able to write a new version that allows individual settings for each LED triad and then do what you need them to do. Since it’s your assignment and not mine, I leave that part to you. :twisted:

ps : It goes w/o saying that this part will need to change as well, to call whatever new version of colorAppear you come up with.

void loop() {
colorAppear (Color(255, 250, 250), 50);
colorAppear (Color(0, 0, 0), 5000);
}

So if you understand the above (and if I’m correct in my guesses) then you should be able to predict what the code you posted will do. Run that code and see if it does what you think it should !

Thanxxxxxxxxxxxxxxxxxxxxxxxx alot.

I added another function ( colorDisappear ). However I could not manage to change the last LEDs into red and then turn them off. it turns each red and then off.

[void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {

for (int j=0; j < strip.numPixels(); j++) {

if (j < 28){

strip.setPixelColor(j, c1);

strip.show();

delay(wait1);

}

else {

strip.setPixelColor(j, c2);

strip.show();

delay(wait2);

strip.setPixelColor(j, c1);

strip.show();

delay(wait1);]

I also tried this one which doesn’t work. I could not find why!!!

[void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {

for (int j=0; j < strip.numPixels(); j++) {

if (j < 28){

strip.setPixelColor(j, c1);

strip.show();

delay(wait1);

}

else {

strip.setPixelColor(j, c2);

strip.show();

delay(wait2);

if (j = strip.numPixels()){

for (int k=28; k < strip.numPixels(); k++) {

strip.setPixelColor(k, c1);

strip.show();

delay(wait1);

}

}

}

}

}]

and the void loop is:

[void loop() {

colorAppear (Color(255, 255, 255), 50);

colorDisappear (Color(0, 0, 0),50000, Color(255, 0, 0) , 50);

}]

I really appreciate all your helps.

I also have one more question.

Do you maybe know if it is possible to cut a meter of LED strip [10312] into pieces, and if so from which part it would be possible.

Regards

mahban.irandoust:
I added another function ( colorDisappear ). However I could not manage to change the last LEDs into red and then turn them off. it turns each red and then off.

 [void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {

for (int j=0; j < strip.numPixels(); j++) {
if (j < 28){
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);
}
else {
strip.setPixelColor(j, c2);
strip.show();
delay(wait2);
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);]

What were you trying to do with the above ? Originally you said :

mahban.irandoust:
I need a program to turn on all LEDs (32 LEDs) in white color and afterwards turining them off (one by one). when this (turn-off) reaches to the last 6 LEDs, switch their color into pink and then turn them off.

again, when "turn-off’reaches to the last 2 LEDs, switch thir color into red and then turn them off.

You now say “However I could not manage to change the last LEDs into red and then turn them off. it turns each red and then off.” Huh ? Let me make sure I understand. Now you want some number of the “last” LEDs to all turn red and then, after some time, all turn off. What you’re getting is each of the “last” LEDs turns red and then off and then the next LED does the same, etc, etc. I’d expect this latter behavior given your code above. Look at this part :

else {
      strip.setPixelColor(j, c2);
      strip.show();
      delay(wait2);
      strip.setPixelColor(j, c1);
      strip.show();
      delay(wait1);]

Let j = 28 and what happens ? The code executes the above just as you wrote it. It sets pixel 29 to color c2 (red) then waits “wait2” msecs then sets pixel 29 to color c1 (off) and waits “wait1” msecs before incrementing j and doing it for the next pixel.

I note that 32 pixels (1-32) are controlled by j from 0-31 and j = 28 doesn’t correspond to either the last 6 or the last 2 pixels.

mahban.irandoust:
I also tried this one which doesn’t work. I could not find why!!!

[void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {

for (int j=0; j < strip.numPixels(); j++) {
if (j < 28){
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);
}
else {
strip.setPixelColor(j, c2);
strip.show();
delay(wait2);
if (j = strip.numPixels()){
for (int k=28; k < strip.numPixels(); k++) {
strip.setPixelColor(k, c1);
strip.show();
delay(wait1);
}
}
}
}
}]

So what did the above do ? Hint : what’s the largest value j can get to and still have the code above execute ?

http://www.arduino.cc/en/Reference/For

mahban.irandoust:
and the void loop is:

[void loop() {

colorAppear (Color(255, 255, 255), 50);
colorDisappear (Color(0, 0, 0),50000, Color(255, 0, 0) , 50);
}]



I really appreciate all your helps.

I would do things differently but there are many ways to do what you want (though I’m not sure exactly what that is now). One thing I will point out, and I think it was wrong in the library code as well, is that the “wait” variable was declared as an unsigned 8 bit value. That can only store a number up to 255. I don’t know what happens when you try to stuff a delay greater than 255 into it.

Hi and thank you very much for all your help.

I have a short question do you maybe know if it is possible to cut addressable LED strip [sku: COM-10312] into pieces, and if so from which part it would be possible.

I really appreciate all your helps.

Regards

mahban.irandoust:
Hi and thank you very much for all your help.

I have a short question do you maybe know if it is possible to cut addressable LED strip [sku: COM-10312] into pieces, and if so from which part it would be possible.

I really appreciate all your helps.

Regards

Did you even bother to read the product page ?

http://www.sparkfun.com/products/10312