LPD8806 questions.....
Moderators: adafruit_support_bill, adafruit

LPD8806 questions.....

by slurry bowl on Sun Jan 13, 2013 2:35 am

Hello good people.

I have made great strides in understanding the existing libraries for the LPD8806.

THANKS ADAFRUIT.

I am trying to understand the advanced belt kit code and it is over my head.

I love how the patterns fade into each other, working with channels, etc....

I am trying to write some code that would do this:

1. Divide the total LED strip into 2 lengths, its continuous, so in code, separate them.
- both divisions would fade between magenta, turquoise, and blue, but rotate through those colors so often the 2 sides of the strip are in opposition(turquoise/magenta) (blue/magenta), etc...and occasionally they are the same.

what function does a fade between colors? is there one?

any input would be much appreciated. Thanks !!! cant wait to post some pics of my project!
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 5:37 pm

Re: LPD8806 questions.....

by pburgess on Sun Jan 13, 2013 8:26 pm

You can always use the Arduino 'map' function to interpolate between two values...then do this separately each for red, green and blue:

Code: Select all | TOGGLE FULL SIZE
// Magenta:
#define COLOR1_R 255
#define COLOR1_G 0
#define COLOR1_B 255
// Blue:
#define COLOR2_R 0
#define COLOR2_G 0
#define COLOR2_B 255

top = 42; // maximum value of counter
x = (some value from 0 to 'top');
r = map(x, 0, top, COLOR1_R, COLOR2_R);
g = map(x, 0, top, COLOR1_G, COLOR2_G);
b = map(x, 0, top, COLOR1_B, COLOR2_B);


A fair bit of math can be saved if you know certain components are the same between the colors (e.g. only red varies in the above example, so the green and blue calculations could be left out altogether, just using the constants in their place.
User avatar
pburgess
 
Posts: 2525
Joined: Sun Oct 26, 2008 1:29 am

Re: LPD8806 questions.....

by slurry bowl on Tue Jan 22, 2013 12:00 pm

Thanks Phil,

I keep trying to put the map function in the code, assuming its supposed to work in the ADVANCED LED BELT KIT code.

I attempted to define Top because I was getting an error message and decided in the setup it needed to be an int.

Feeling lost on how to achieve this simple task of color fading.

Can you recommend any tutorials?
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 5:37 pm

Re: LPD8806 questions.....

by pburgess on Tue Jan 22, 2013 1:05 pm

Ah yeah, I'm sorry about that...that was supposed to be just fake and incomplete pseudocode to give an idea, and wouldn't actually compile as-is. But yes, declaring 'top' as an int would probably work, or you can use a #define since the value won't be changing.

Also, think I goofed on the color values...with the LPD8806, these should top out at 127 (brighest) rather than 255.
User avatar
pburgess
 
Posts: 2525
Joined: Sun Oct 26, 2008 1:29 am

Re: LPD8806 questions.....

by slurry bowl on Tue Jan 22, 2013 9:44 pm

seems 255 is the right #.

Out of all the example codes in the LPD8806 library, which would be the easiest to add this code into?
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 5:37 pm

Re: LPD8806 questions.....

by pburgess on Wed Jan 23, 2013 2:53 am

I'd start with 'strandtest', it's just about the easiest case. In fact the standard belt code is just this with a few extra bells & whistles added.
User avatar
pburgess
 
Posts: 2525
Joined: Sun Oct 26, 2008 1:29 am

Re: LPD8806 questions.....

by slurry bowl on Thu Jan 24, 2013 10:18 pm

Well, Im making progress. Ive still got some abrupt changes, but Im learning alot.
Just to restate, I want to fade between, BLUE, MAGENTA, TURQUOISE.
This is the current code:

void loop() {
int r,g,b;
uint16_t i, j;

for (j=0; j < 40; j++) {
r = map(j, 0, 40, COLOR1_R, COLOR2_R);
g = map(j, 0, 40, COLOR1_G, COLOR2_G);
b = map(j, 0, 40, COLOR1_B, COLOR2_B);

for (i=0; i < 2; i++) {
strip.setPixelColor(i,(strip.Color(r,g,b) ));
}

strip.show(); // write all the pixels out
delay(100);
}

for (j=0; j < 40; j++) {
r = map(j, 0, 40, COLOR2_R, COLOR1_R);
g = map(j, 0, 40, COLOR2_G, COLOR1_G);
b = map(j, 0, 40, COLOR2_B, COLOR1_B);

for (i=0; i < 2; i++) {
strip.setPixelColor(i,(strip.Color(r,g,b) ));
}

strip.show(); // write all the pixels out
delay(100);
slurry bowl
 
Posts: 122
Joined: Sun Nov 11, 2012 5:37 pm