LPD8806 Basic

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
slurry bowl
 
Posts: 156
Joined: Sun Nov 11, 2012 6:37 pm

LPD8806 Basic

Post by slurry bowl »

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. !

User avatar
slurry bowl
 
Posts: 156
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

Post by slurry bowl »

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!

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: LPD8806 Basic

Post by adafruit_support_bill »

Code: Select all

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
slurry bowl
 
Posts: 156
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

Post by slurry bowl »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: LPD8806 Basic

Post by adafruit_support_rick »

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

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

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

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

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

User avatar
slurry bowl
 
Posts: 156
Joined: Sun Nov 11, 2012 6:37 pm

Re: LPD8806 Basic

Post by slurry bowl »

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.

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: LPD8806 Basic

Post by adafruit_support_bill »

-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

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

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();
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”