Pages: [1]   Go Down
 Author Topic: LPD8806 - Sine Wave vs Pulse effect  (Read 1072 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 29
 « on: July 12, 2013, 08:51:42 am » Bigger Smaller Reset

I had figured this out on a previous project for halloween, but I lost my original code and now Im banging my head on how I figured it out before.

I have LPD8806 strip of LEDS.  I want to get the "pulse" effect, where the entire strip goes on and off via the Sine wave.. nice smooth transition.

The Wave effect does this, but it passes through the entire strip.  I just want to modify it to do the same for every LED at the same time.  I'm fairly certain that I did a simple modification to the Wave function to do this the last time.  If i didnt, its probably why Im not figuring this out.

Code:
// Sine wave effect
#define PI 3.14159265
void wave(uint32_t c, int cycles, uint8_t wait) {
float y;
byte  r, g, b, r2, g2, b2;

// Need to decompose color into its r, g, b elements
g = (c >> 16) & 0x7f;
r = (c >>  8) & 0x7f;
b =  c        & 0x7f;

for(int x=0; x<(strip.numPixels()*5); x++)
{
for(int i=0; i<strip.numPixels(); i++) {
y = sin(PI * (float)cycles * (float)(x + i) / (float)strip.numPixels());
if(y >= 0.0) {
// Peaks of sine wave are black
y  = 1.0 - y; // Translate Y to 0.0 (top) to 1.0 (center)
r2 = (byte)((float)r * y);
g2 = (byte)((float)g * y);
b2 = (byte)((float)b * y);
} else {
// Troughs of sine wave are black
y += 1.0; // Translate Y to 0.0 (bottom) to 1.0 (center)
r2 = (byte)((float)r * y);
g2 = (byte)((float)g * y);
b2 = (byte)((float)b * y);
}
strip.setPixelColor(i, r2, g2, b2);
}
strip.show();
delay(wait);
}
}

This post is my last resort before I let this tiny thing make me go crazy.

Help?
 Logged

Chicago
Offline
Sr. Member
Karma: 5
Posts: 456
With every answer comes more questions.
 « Reply #1 on: July 13, 2013, 02:57:37 pm » Bigger Smaller Reset

Have you taken a recent look at the updated Adafruit libraries & example code for LPD8806?
 Logged

Offline
Newbie
Karma: 0
Posts: 29
 « Reply #2 on: July 15, 2013, 03:15:44 pm » Bigger Smaller Reset

Updated libraries? where is this?
Ive been looking to the original one and it hasnt been updated in a while now..

 Logged

Chicago
Offline
Sr. Member
Karma: 5
Posts: 456
With every answer comes more questions.
 « Reply #3 on: July 16, 2013, 01:33:10 pm » Bigger Smaller Reset

Well, updated since last Halloween anyway.

I assume, then, you've seen this example code -

Code:
// Fill the entire strip with...
colorWipe(strip.Color(127,   0,   0), 50);  // Red
colorWipe(strip.Color(  0, 127,   0), 50);  // Green
colorWipe(strip.Color(  0,   0, 127), 50);  // Blue

Just to be sure what you want to do....
Do you want the entire strip to the same color at any given point in time? Cycling through the colors, or fading a single color on & off?

I don't have that LED strip to test anything. Sorry. Just trying to help you find solution.
 Logged

Offline
Newbie
Karma: 0
Posts: 29
 « Reply #4 on: July 22, 2013, 03:19:52 pm » Bigger Smaller Reset

appreciate the help.

I want the color to "pulse" on and off.  So which ever color will start off, slowly fade on, then slowly fade back to off

Im still kicking myself for losing my code..   I think in the wave effect I might need to made the number of cycles = number of LEDs.. my original solution was something stupid simple.. sigh

I'll have more time to troubleshoot myself this week, have a deadline for needing wanting this by the 31st.
 Logged

Offline
Newbie
Karma: 0
Posts: 10
 « Reply #5 on: July 26, 2013, 09:16:07 am » Bigger Smaller Reset

You might take a look at these:

and

 Logged

Offline
Newbie
Karma: 0
Posts: 29
 « Reply #6 on: July 29, 2013, 08:31:27 am » Bigger Smaller Reset

Found it.. and it was a simple fix as I thought.

Old code line:
Code:
y = sin(PI * (float)cycles * (float)(x + i) / (float)strip.numPixels());

new code line:
Code:
y = sin(PI * (float)cycles * (float)(x + i));

Playing with the cycles and x variables changes how the sine wave fades.

 Logged

 Pages: [1]   Go Up