LPD8806 Basic
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- slurry bowl
- Posts: 156
- Joined: Sun Nov 11, 2012 6:37 pm
LPD8806 Basic
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: 156
- Joined: Sun Nov 11, 2012 6:37 pm
Re: LPD8806 Basic
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!
for (int i = 0; i < 160; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}
although it sometimes does not work. argh!
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: LPD8806 Basic
Code: Select all
for (int i = 0; i < 160; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}
- slurry bowl
- Posts: 156
- Joined: Sun Nov 11, 2012 6:37 pm
Re: LPD8806 Basic
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.
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.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LPD8806 Basic
The memory issue is related to the line of code where you set up the strip. It will look something like this:
You want to make sure that the number for nLEDs is 4, not 160
Also, this for loop is not correct:
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:
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
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);
Also, this for loop is not correct:
Code: Select all
for (int i = 0; i < 4; ){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}
Code: Select all
for (int i = 0; i < 4; i++){
strip.setPixelColor(i, 50, 0,0);
strip.show();
}
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();
- slurry bowl
- Posts: 156
- Joined: Sun Nov 11, 2012 6:37 pm
Re: LPD8806 Basic
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.
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.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: LPD8806 Basic
Use the parameters of the for loop to set the range:-How do I address a section of LEDs using this method, as in LEDs 4-20 are RED 21-30 blue.
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();
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:-You may notice my code increases the #, in the section for (int i = 3, i < #, i ++), is this necessary?
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();
}
Please be positive and constructive with your questions and comments.