LPD8806 - Sine Wave vs Pulse effect

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.

// 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);

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


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

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

Well, updated since last Halloween anyway. :cold_sweat:

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

This bit isn't helpful?

  // 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.

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.

You might take a look at these:


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

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

Old code line:

y = sin(PI * (float)cycles * (float)(x + i) / (float)strip.numPixels());

new code line:

y = sin(PI * (float)cycles * (float)(x + i));

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