Go Down

### Topic: LPD8806 - Sine Wave vs Pulse effect (Read 1 time)previous topic - next topic

#### tekket

##### Jul 12, 2013, 03:51 pm
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: [Select]
`// Sine wave effect#define PI 3.14159265void 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?

#### 1ChicagoDave

#1
##### Jul 13, 2013, 09:57 pm
Have you taken a recent look at the updated Adafruit libraries & example code for LPD8806?

#### tekket

#2
##### Jul 15, 2013, 10:15 pm
Updated libraries? where is this?
Ive been looking to the original one and it hasnt been updated in a while now..

#### 1ChicagoDave

#3
##### Jul 16, 2013, 08:33 pm
Well, updated since last Halloween anyway.

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

This bit isn't helpful?
Code: [Select]
`  // 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.

#### tekket

#4
##### Jul 22, 2013, 10:19 pm
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.

#### teaker

#5
##### Jul 26, 2013, 04:16 pm
You might take a look at these:

and

http://www.adafruit.com/forums/viewtopic.php?f=47&p=169883       <--- macbook-style breathing effect

#### tekket

#6
##### Jul 29, 2013, 03:31 pm
Found it.. and it was a simple fix as I thought.

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

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

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

Go Up