LPD8806 Basic
Moderators: adafruit_support_bill, adafruit

LPD8806 Basic

by slurry bowl on Sun Nov 11, 2012 6:43 pm

I bought a strip from Adafruit and I can get the STRANDTEST as well as other examples to work. I want to be able to customize the colors of specific stretches of the strip. Im not interested in flashy animations, but simply to assign a color to a specific LED. How is this done? WHen I try to hack into the test codes, I seem to erase too much, receiving many error messages. Thanks for any help. !
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

by slurry bowl on Mon Nov 12, 2012 2:00 am

I can occasionally get addressing. By using :



for (int i = 0; i < 160; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}


although it sometimes does not work. argh!
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

by adafruit_support_bill on Mon Nov 12, 2012 7:19 am

Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 160; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}


How big is your strip? That loop is for a 160 pixel strip. If you have 160 pixels you are probably running out of memory and things will not work reliably.
User avatar
adafruit_support_bill
 
Posts: 31061
Joined: Sat Feb 07, 2009 10:11 am

Re: LPD8806 Basic

by slurry bowl on Mon Nov 12, 2012 10:56 am

My strip is much smaller. Currently 4 LEDs on strip. I understand that i designates the LED #.

I assume that my code should look:


for (int i = 0; i < 4; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}

REally appreciate the beautiful strips and advice on code. Truly a pleasure to work with Adafruit.
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

by adafruit_support_rick on Mon Nov 12, 2012 11:05 am

The memory issue is related to the line of code where you set up the strip. It will look something like this:
Code: Select all | TOGGLE FULL SIZE
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);


You want to make sure that the number for nLEDs is 4, not 160

Also, this for loop is not correct:
Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 4; ){
  strip.setPixelColor(i, 50, 0,0);
  strip.show();
}


You need three things inside the parentheses after for: the starting value of your loop variable, the test for the end of the loop, and something to change the value of the loop variable. You're missing that last part. Your code should look like this:
Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 4; i++){
  strip.setPixelColor(i, 50, 0,0);
  strip.show();
}


The i++ increments the value of i by 1 each time through the loop.

Finally, your loop calls strip.show() every time through. You only need to call it once, after all the pixels are set:
Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 4; i++){
  strip.setPixelColor(i, 50, 0,0);
}
strip.show();

adafruit_support_rick
 
Posts: 13080
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: LPD8806 Basic

by slurry bowl on Tue Nov 13, 2012 12:15 am

Thanks Driverblock and Adafruit.

I am progressing and I have been able to get individual addressing by using this code I thought up:

void loop() {

for (int i = 0; i < 1; i++){
strip.setPixelColor(i, 10, 0,0);
}
for (int i = 1; i < 2; i++){
strip.setPixelColor(i, 0, 10,0);
}
for (int i = 2; i < 3; i++){
strip.setPixelColor(i, 0, 0,10);
strip.show();
}
for (int i = 3; i < 4; i++){
strip.setPixelColor(i, 0, 10,10);
strip.show();
}


A few questions:

-How do I address a section of LEDs using this method, as in LEDs 4-20 are RED 21-30 blue.

-You may notice my code increases the #, in the section for (int i = 3, i < #, i ++), is this necessary?

Thanks for all the help, I will post photos of my project when Im done.
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

by adafruit_support_bill on Tue Nov 13, 2012 7:03 am

-How do I address a section of LEDs using this method, as in LEDs 4-20 are RED 21-30 blue.

Use the parameters of the for loop to set the range:
Code: Select all | TOGGLE FULL SIZE
for (int i = 4; i <= 20; i++) // leds 4-20
{
  strip.setPixelColor(i, 255, 0,0);  // set red
}
for (int i = 21; i <= 30; i++)  // leds 21-30
{
  strip.setPixelColor(i, 0, 0,255);  // set blue
}
strip.show();

-You may notice my code increases the #, in the section for (int i = 3, i < #, i ++), is this necessary?

It is if you use a for loop and the '<' operator to test the termination condition. But for a single led, your code can be simplified quite a bit. To set a single pixel, you don't need the loop at all. You can write the same thing in 5 lines:
Code: Select all | TOGGLE FULL SIZE
void loop()
{
  strip.setPixelColor(0, 10, 0,0);
  strip.setPixelColor(1, 0, 10,0);
  strip.setPixelColor(2, 0, 0,10);
  strip.setPixelColor(3, 0, 10,10);

  strip.show();
}
User avatar
adafruit_support_bill
 
Posts: 31061
Joined: Sat Feb 07, 2009 10:11 am