How to address each LED alone [LPD8806]
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 3
- Joined: Sun Sep 30, 2012 9:28 pm
How to address each LED alone [LPD8806]
Well, I've had my LED belt set for a good while now, and everyone at my school just loves it. But I've never understood how to program each LED on it's own. I mean, like make it so i can set all 30 (lost 2 of em) to a specific color. If more detail is needed, ask away . Thank you all for the help
- adafruit_support_bill
- Posts: 88090
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to address each LED alone [LPD8806]
To set a single pixel, use the "setPixelColor(pixel, color)" function. The 'pixel' parameter is the number of the pixel you want to set and 'color' is the RGB color you want to set it to. The "Color(r, g, b)" function is used to create the RGB color value.
For example:
For example:
Code: Select all
strand.setPixelColor(5, strand.Color(255, 0, 0)); // set pixel #5 Red
strand.setPixelColor(6, strand.Color(0, 255, 0)); // set pixel #6 Green
strand.setPixelColor(7, strand.Color(0, 0, 255)); // set pixel #7 Blue
strand.setPixelColor(8, strand.Color(255, 255, 255)); // set pixel #8 White
strand.setPixelColor(9, strand.Color(0, 0, 0)); // set pixel #9 Black
-
- Posts: 3
- Joined: Sun Sep 30, 2012 9:28 pm
Re: How to address each LED alone [LPD8806]
That seems fairly simple. How I missed it, I don't know. But how would I go about making some code like what came with the demos, so it actually rotates around the belt, or makes a scanning motion like the police scanner?adafruit_support wrote:To set a single pixel, use the "setPixelColor(pixel, color)" function. The 'pixel' parameter is the number of the pixel you want to set and 'color' is the RGB color you want to set it to. The "Color(r, g, b)" function is used to create the RGB color value.
For example:
Code: Select all
strand.setPixelColor(5, strand.Color(255, 0, 0)); // set pixel #5 Red strand.setPixelColor(6, strand.Color(0, 255, 0)); // set pixel #6 Green strand.setPixelColor(7, strand.Color(0, 0, 255)); // set pixel #7 Blue strand.setPixelColor(8, strand.Color(255, 255, 255)); // set pixel #8 White strand.setPixelColor(9, strand.Color(0, 0, 0)); // set pixel #9 Black
- adafruit_support_bill
- Posts: 88090
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to address each LED alone [LPD8806]
Have you read the code that comes with the demos? You will notice that it mostly makes use of the "for" statement to create the patterns. The 'for' statement is documented here: http://arduino.cc/en/Reference/Forhow would I go about making some code like what came with the demos
-
- Posts: 3
- Joined: Sun Sep 30, 2012 9:28 pm
Re: How to address each LED alone [LPD8806]
I've looked at the code, mostly. I was mainly confused by theadafruit_support wrote:Have you read the code that comes with the demos? You will notice that it mostly makes use of the "for" statement to create the patterns. The 'for' statement is documented here: http://arduino.cc/en/Reference/Forhow would I go about making some code like what came with the demos
Code: Select all
void colorChase(uint32_t c, uint8_t wait);
-
- Posts: 2
- Joined: Sun Jan 27, 2013 2:13 am
Re: How to address each LED alone [LPD8806]
Found this post.
along with suggested code.
How would one not only address each LED indivually but also set its brightness in the same line?
I found another post that says to control the brightness you use the setPixelColor() 0=off and 255 is MAX
How do I find the setPixelColor() syntax / options?
Thans in Advance!
along with suggested code.
How would one not only address each LED indivually but also set its brightness in the same line?
Code: Select all
strand.setPixelColor(5, strand.Color(255, 0, 0)); // set pixel #5 Red
strand.setPixelColor(6, strand.Color(0, 255, 0)); // set pixel #6 Green
strand.setPixelColor(7, strand.Color(0, 0, 255)); // set pixel #7 Blue
strand.setPixelColor(8, strand.Color(255, 255, 255)); // set pixel #8 White
strand.setPixelColor(9, strand.Color(0, 0, 0)); // set pixel #9 Black
How do I find the setPixelColor() syntax / options?
Thans in Advance!
- adafruit_support_bill
- Posts: 88090
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to address each LED alone [LPD8806]
Just as in the code fragment you posted. The first argument is the pixel number, the second argument is the color.How would one not only address each LED indivually but also set its brightness in the same line?
The color is composed of 3 parts: Red, Green and Blue. By adjusting the values of the R, G & B between 0 (off) and 255(maximum intensity) you can control the color of the pixel.
-
- Posts: 2
- Joined: Sun Jan 27, 2013 2:13 am
Re: How to address each LED alone [LPD8806]
Yes I think I understand the color property.
But say I want RED then the next time I want red at at half the intensity or even .25 the intensity. are you saying the code would look like this.
But say I want RED then the next time I want red at at half the intensity or even .25 the intensity. are you saying the code would look like this.
Code: Select all
strand.setPixelColor(0, strand.Color(255, 0, 0)); // set pixel #0 100%FULL Red
strand.setPixelColor(1, strand.Color(127, 0, 0)); // set pixel #1 50% intensity Red
strand.setPixelColor(2, strand.Color(65, 0, 0)); // set pixel #5 25% intensity Red[/code
- adafruit_support_bill
- Posts: 88090
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to address each LED alone [LPD8806]
Yes - mostly. The catch is that neither the leds nor your retinas respond linearly. You will have to experiment a bit to find the value the "looks" like half intensity.
-
- Posts: 33
- Joined: Thu Dec 20, 2012 9:33 am
Re: How to address each LED alone [LPD8806]
You can also hijack the 'hsv2rgb' function from the advanced belt kit.
Copy that function out to your code, and then use something like...
with this, you can just set the brightness with level, no matter what hue you choose.
No guesswork!!
Copy that function out to your code, and then use something like...
Code: Select all
long color, hue, saturation, level;
hue = 0; //0 - 1536 where 0=red 512=green 1024=blue
saturation = 255; //0 - 255 where 255 is full colour, and 0 is white
level = 255; 0 - 255: where 255 is brightest, and 0 is dimmest
color = hsv2rgb(hue, saturation, level);
strand.setPixelColor(0, strand.Color(color >> 16, color >> 8, color));
No guesswork!!
- mohawkpiper
- Posts: 138
- Joined: Sat Oct 13, 2012 3:28 am
Re: How to address each LED alone [LPD8806]
talking about the colors not looking linear...adafruit_support wrote:Yes - mostly. The catch is that neither the leds nor your retinas respond linearly. You will have to experiment a bit to find the value the "looks" like half intensity.
a bias function will fix this.
here is one i use quite often, it is written to be used in a for loop though, for creating a fading "trail" of pixels after the original full brightness one. but it can be re-written for a single pixel.
Code: Select all
uint32_t fade_color(uint32_t color, int decay, int current, float BIAS) {
//Decompose
byte g = color >> 16 & 0x7f;
byte r = color >> 8 & 0x7f;
byte b = color & 0x7f;
//do our math
float thisDecay = pow( (((float)decay) - current) / decay, log(BIAS)/log(0.5) );
g = (byte) ((float) g) * thisDecay;
r = (byte) ((float) r) * thisDecay;
b = (byte) ((float) b) * thisDecay;
//recompose and return
return (g << 16) + (r << 8) + b;
}
'decay' is how many pixels are in your fading "trail".
'current' is the pixel in that trail that you are on.
'BIAS' is the bias you would like.
i found a bias of 0.1 or 0.15 works well to make it look pretty linear in fading it.
NOTE: the thisDecay function is pretty slow, especially for longer "tails", so if speed in your LEDs is what you need, this isnt the best way to do it. I couldnt figure out something that worked pretty fast that did something similar.
Please be positive and constructive with your questions and comments.