Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bunger
 
Posts: 89
Joined: Sun Apr 10, 2011 2:33 pm

Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by bunger »

I am trying to write code to slowly dim up a strand of the 12mm RGB LEDs, dim them back down, and then loop that... but for some reason ( I'm probably just tired ) I can't get the code to do the ramp up and down. The problem is that no matter what I put for the Delay value, the entire strand immediately lights up instead of slowly "brightening." Any thoughts on what I am missing here?

Thanks in advance!!
Bill

Code: Select all

void loop() {
  redPulse(500);
}


void redPulse(uint8_t wait) {
  //  SET UP VARS
  int i, j, red, green, blue;
  red = 0;
  green = 0;
  blue = 0;
  
  // IDEALLY SLOWLY RAMP UP THE COLOR PURPLE BY INCREMENT THE RED AND BLUE VALUES BY 1
  for (j=0; j<255; j++ ) { 
    //  DON'T NEED THIS, BUT MAKES IT EASIER TO DEBUG
    red = j;
    
    //  LOOP THROUGH ALL LEDS ON STRIP AND SET THE COLOR VALUE
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Color(red, green, blue));
      }
    } 
   //  LIGHT UP THE STRIP WITH APPROPRIATE COLOR
   strip.show();   // write all the pixels out
  //  WAIT A LITTLE WHILE BEFORE RAMPING UP TO THE NEXT COLOR INCREMENT
   delay(500);  
}

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by Franklin97355 »

To start you are missing the setup() clause. could you include the entire program with as many comments as possible?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by adafruit_support_mike »

When you fade LEDs, there's a theoretical point you'll run into: the human eye doesn't respond to light in a linear manner.

We don't perceive twice as much light being twice as bright. If we did, we'd be blind most of the time. The difference between full sunlight and full moonlight is something like 20,000:1. Instead, our eyes respond logarithmically.. we see twice as much light as 'one step brighter', so you need to double the amount of light again to get another step brighter.

You'll get what looks like a linear fade from code like this:

Code: Select all

    for (int i=1 ; i < 1024 ; i<<1) {
        for (j=0; j < strip.numPixels(); j++) {
            strip.setPixelColor(j, Color(i, i, i));
        }
    }

User avatar
bunger
 
Posts: 89
Joined: Sun Apr 10, 2011 2:33 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by bunger »

I just inserted your suggested code and LEDs just essentially stay at a dim bluish hue without any fading. Any other thoughts?



Code: Select all

  for (int i=1 ; i < 1024 ; i<<1) {
    for (j=0; j < strip.numPixels(); j++) {
      strip.setPixelColor(j, Color(i, i, i));
    }
   strip.show();   // write all the pixels out
   delay(500); 
  } 

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by adafruit_support_mike »

Typo on my part: I shifted the bits in `i` but didn't store them back to the variable. I also had a fencepost condition that wouldn't take `i` all the way to its brightest value.

Try this:

Code: Select all

    for (int i=1 ; i < 1025 ; i<<=1) {
        for (j=0; j < strip.numPixels(); j++) {
            strip.setPixelColor(j, Color(i-1, i-1, i-1));
        }
    }

EternalCore
 
Posts: 239
Joined: Tue Jul 30, 2013 3:57 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by EternalCore »

@OP: hi, Here's 2 fade in/out examples I made, for the NeoPixels but they can easily be adapted for the WWS2801 strips, that you may use:

This is a simple example:

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
  int R = 0;
  int G = 0;
  int B = 0;
  //Fade in
  for(R && G && B; R<126 && G<126 && B<126; R++ && G++ && B++) {
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    delay(1);
  }
  //Fade Out
  for(R && G && B; R>-1 && G>-1 && B>-1; R-- && G-- && B--) {
    for(int j=0; j<strip.numPixels(); j++) {
      strip.setPixelColor(j, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    delay(1);
  }
}
And here's a more complex example:

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
  int R = 0;
  int G = 0;
  int B = 0;
  int finCount=5;
  int foutCount=5;
  int Rset = 125;
  int Gset = 125;
  int Bset = 125;
  int waitT = 5;
  //Fade in
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
    //break the inf loop if the color is higher then what its set at.
    if (R>Rset+1 && G>Gset+1 && B>Bset+1)  { 
      //ReSet the RGB to set values. 
      R=Rset;
      G=Gset;
      B=Bset;
      break; 
    } 
    //update the strip
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //increase by the set amount
    R=R+finCount;
    G=G+finCount;
    B=B+finCount;
    delay(waitT);
  }
  //Fade Out
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
  //break the inf loop if the color is off
    if (R<0 && G<0 && B<0)  { 
      //ReSet the RGB to 0 values. 
      R=0;
      G=0;
      B=0;
      break; 
    } 
    //update the strip
    for(int j=0; j<strip.numPixels(); j++) {
      strip.setPixelColor(j, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //Decrease by the set amount
    R=R-foutCount;
    G=G-foutCount;
    B=B-foutCount;
    delay(waitT);
  }
}
-Enjoy

User avatar
bunger
 
Posts: 89
Joined: Sun Apr 10, 2011 2:33 pm

Re: Slow Pulse of 12mm RGB LEDs ( WWS2801 )

Post by bunger »

adafruit_support_mike wrote:Typo on my part: I shifted the bits in `i` but didn't store them back to the variable. I also had a fencepost condition that wouldn't take `i` all the way to its brightest value.
This worked well, though the ramp up wasn't smooth... but it did do the job!

EternalCore wrote:@OP: hi, Here's 2 fade in/out examples I made, for the NeoPixels but they can easily be adapted for the WWS2801 strips, that you may use:
The more complex example is exactly what I was looking for!! Thanks a ton!!!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”