LED effects - Fade ...
 
Share:
Notifications
Clear all

LED effects - Fade out on rainbow cycle

5 Posts
3 Users
2 Likes
3,353 Views
(@arnaud)
Active Member
Joined: 3 years ago
Posts: 5
Topic starter  

Hello,

As I explained it I would like to add a fade out a the end of the rainbow cycle effect to have a transition between rainbow and meteor rain.

I tested with a FastLED.setBrightness() and with a strip.setBrightness(), unfortunately in the both cases the led strip freezes.

I tried the code hereafter, it works to fade in not to fade out.
In fade out version, all the led decrease to become black but just after the led light up again and the color of each led seems to change randomly but gradually. 

//fadeInRainbow
void fadeInRainbow(int SpeedDelay) {

  byte *c;
  uint16_t i, j;
  for(j = 0; j < 256; j=j+1) {
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel((i * 256 / NUM_LEDS) & 255);
      setPixel(i, *c*(j/256.0), *(c+1)*(j/256.0), *(c+2)*(j/256.0));
    }
 
    showStrip();
    delay(SpeedDelay);
  }
}

//fadeOutRainbow
//WORK IN  PROGRESS
void fadeOutRainbow(int SpeedDelay) {

  byte *c;
  uint16_t i, j;
  for(j = 255; j >= 0; j=j-2) {
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel((i * 256 / NUM_LEDS) & 255);
      setPixel(i, *c*(j/256.0), *(c+1)*(j/256.0), *(c+2)*(j/256.0));
    }
 
    showStrip();
    delay(SpeedDelay);
  }
}

 

The best transition I found is to remove the reset of the LED strip at the beginning of the meteor rain code. Remove of setAll(0,0,0)
But it's not a fade out.

 

Unfortunately I forgot to film the version of the code above.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 10 years ago
Posts: 2504
 

Thanks Arnaud for taking the time and effort to post this in the forum - it is much appreciated 😊 

Thanks for the very cool video! I like what you've done! 👍 
Would you mind sharing the full code once we have it all working?

I think I may have misunderstood your earlier question, so let's try again ...

We probably should consider using the fadeToBlack function.
You can use the function of my project, or the FastLED build-in function.
(I prefer the FastLED library, so if you're going that route, we can eventually cleanup the code and remove the code for NeoPixel)

So this could look something like this:

void fadeOutRainbow(int SpeedDelay) {

// 20 times reduce the color brightness by 25%, reaching close to zero (black)
for(int j=1; j<20; j++) {
   for(int i=0; i< NUM_LEDS; i++) {
     fadeToBlack(i, 64);
    }
 
    showStrip();
    delay(SpeedDelay);
  }
}

Now I haven't tested this code, and there are 2 point to pay attention to;

In the for-j loop, I've used the random value of 20.

In the for-i loop I do a fadeToBlack for all LEDs by 64, which translates to a 64/256 = 25% brightness reduction.
So in each step, the current led value will be reduced by 25%.

So 20 times a 25% reduction, should get a 255 value all the way down to about 1 (which is pretty much "off").
If you really want to absolutely go to zero then you''l need up to 38 steps.
(I didn't use any super genius math for that - I just made a little excel sheet where each row reduces the previous row by 25%)

Note that an x% reduction per step eventually will reach zero, no matter what the starting value/color was. It will never go below zero though.

You'll have to experiment a little to see what values work best for your setup.


   
ReplyQuote
(@arnaud)
Active Member
Joined: 3 years ago
Posts: 5
Topic starter