Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




A Smoother Fadeout ...
 
Share:
Notifications
Clear all

A Smoother Fadeout in MeteorRain (this topic is for Hans <3)

4 Posts
2 Users
0 Likes
120 Views
Joined: 53 years ago
Posts: 0
Topic starter  

Hi! First... HANS, oh, mate, you really helped me A LOT with your trending topic of leds in arduino hahahah i really love you, you help me a lot in the past years... i didn't studied anything abouth electronics, i'm a cosplayer hahaha and i'm upgraded my cosplay level upper than the sky whit you, thank you <3 and you don't only helped me, you helped thousands of cosplayers around the world, i know it hahaha, thousand and thousand of cosplayers are uploading their works thanks to your guide... you made the cosplay world a few levels higher, really <3... i would like have you social media for ask you for an especial arduino request when i need it because i'm not a programmer, i only know a little how to modify code, but i can't create it since 0 hahah
well

MY PROBLEM:

I'm using the "MeteorRain" Effect with the FastLed Library... And the FadeOut effect is very hard, i need make it smoother because i'm using this effect a little slow...
I Just modify the values of the MeteorRain for make it red and smaller, but a smoother FadeOut (and fadeIn) is possible because i can do it with the rainbowCycle in NeoPixel, i'll bring you both codes below, but this video it will explain it better than me... Video Example

Can you make an smoother fadeIn and Out with the MeteorRain? Or add a "random" improvement for the NeoPixel RainbowCycle when it fade out maybe...

My current code:

#include "FastLED.h"
#define NUM_LEDS 25
CRGB leds[NUM_LEDS];
#define PIN 9

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}



void loop() {
  meteorRain(255,0,0,7,150, true, 100);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;
   
    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
   
    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif  
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

The RainbowCycle with NeoPixel code:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 4

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

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

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

void loop() {

  rainbowCycle(9);
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  for(j=256; j<256*5; j--) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 0, 0 );
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, 0 );
  }
  WheelPos -= 170;
  return strip.Color(0, 0, 0);
}
This topic was modified 1 month ago by

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

Hey there! And a happy New Year 😁 

Oh man, those are some really nice compliments - they do make my day.
Cosplay has been on my "I'd love top try that one day" list. Share some pics if you can! I'm always amazed by the creativity that comes with cosplay.

Not sure what you mean though with "i would like have you social media"?

So when looking at your video (which looks really cool!), my best guess would be trying to display each new LED at half brightness first before updating it to full brightness. This may make the transition smoother.

I used dividing by 2 ( "/2" ) as an example, which may or may not be a good value.
You could try /1.5 (brighter) or /3 (darker), or any value you'd like.

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   setPixel(i, red/2, green/2, blue/2 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

Now having said that, if this is still going too abrupt, then add multiple steps, maybe something like this (just a part of the :

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);

  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {

/////// fade new LED ///////
   
   setPixel(i, red/4, green/4, blue/4 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

   // optionally add a delay here, if this goes too fast, eg "delay(100);"

   setPixel(i, red/3, green/3, blue/3 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

   // optionally add a delay here, if this goes too fast, eg "delay(100);"

   setPixel(i, red/2, green/2, blue/2 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

   // optionally add a delay here, if this goes too fast, eg "delay(100);"

/////// fade new LED ///////

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

 I unfortunately do not have my hardware handy, so I wasn't able to test this myself, but I do hope it helps 😊 


   
ReplyQuote
Joined: 53 years ago
Posts: 0
Topic starter  

@hans Happy new year! <3
hahaha your welcome, it would be great that you start in the cosplay world! you already have the led mastery hahahaha this is my instagram cosplay page , with social media i mean if you have facebook or instagram to text you when i need ask you for a Arduino commission or something like that, i don't know how to create code since 0...

About your new modify of the code this is how looks (the first part of this

), the "fade in" looks to much better, but the "fade out" still going abruptly... i added a lot of steps for make it smoother

setPixel(i, red/4, green/4, blue/4 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

   setPixel(i, red/3.75, green/3.75, blue/3.75 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

   setPixel(i, red/3.5, green/3.5, blue/3.5 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

      setPixel(i, red/3.25, green/3.25, blue/3.25 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

      setPixel(i, red/3, green/3, blue/3 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

   setPixel(i, red/2.75, green/2.75, blue/2.75 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

   setPixel(i, red/2.5, green/2.5, blue/2.5 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

      setPixel(i, red/2.125, green/2.125, blue/2.125 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

         setPixel(i, red/2, green/2, blue/2 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

            setPixel(i, red/1.75, green/1.75, blue/1.75 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

            setPixel(i, red/1.5, green/1.5, blue/1.5 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

            setPixel(i, red/1.25, green/1.25, blue/1.25 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

            setPixel(i, red/1, green/1, blue/1 ); // replace "2" with different number to test, for example 1.5
   showStrip(); // quick in between to make that new LED visible.

delay (10);

The second part of the video is the rainbow cycle with NeoPixel (i know you don't like NeoPixel to much hahaha), it work with a increasing "wheel" of 1 to 256... that make smoother clean steps i think, it would be possible add it a "random" code?

thank you again for answered me this topic <3

This post was modified 4 weeks ago by Hans

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

Nice work on the costumes and such! Really nice!
As for Arduino questions: I do prefer to see them here, so others can benefit from it as well.
I do however rarely work on projects, but if you have a specific question in mind, feel free to email me (reply to this forum notification).

Anyhoo .. coming back to your code; we could probably write this a little shorter, like so:

for(int d=4; d>=1; d=d-0.25) {
  setPixel(i, red/d, green/d, blue/d ); 
  showStrip(); 
  delay (10);
}

Instead of all these repeats: golden rule here is that when you see repetition, a for loop can help out 😁 

We could try to apply a similar trick with this part of the code:

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }

Maybe try something like this:

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay/2 );        
      }
    }

    showStrip(); 
    delay (10);

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay/2 );        
      }
    }

    showStrip(); 
    delay (10);

Not sure how well this will work visually, and the last "showStrip()" and "delay(10)" may be not needed.
Give it a try 😁 

 


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: