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 Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Updated libraries? where is this?
Ive been looking to the original one and it hasnt been updated in a while now..
https://github.com/adafruit/LPD8806


Logged

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, updated since last Halloween anyway.   smiley-roll-sweat

I assume, then, you've seen this example code -
https://github.com/adafruit/LPD8806/blob/master/examples/strandtest/strandtest.pde

This bit isn't helpful?
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 Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might take a look at these:

https://github.com/edelooff/LPD8806-Miniprojects/blob/master/MiniFade/MiniFade.ino

and

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

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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
Jump to: