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!



Problem with revers...
 
Share:
Notifications
Clear all

[Solved] Problem with reverse meteor rain

5 Posts
3 Users
3 Reactions
2,297 Views
(@Anonymous)
Joined: 1 second ago
Posts: 0
Topic starter  

Good day for everyone! i try to do a reverse meteor rain effect in arduino, based on some codes that are on the page, it runs well but at the end the meteor doesnt fade to black, ill share the code and a video

Thanks for stoping by!

https://odysee.com/@Gutss:6/video:3

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = NUM_LEDS-1; i>=meteorSize; 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>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 & 0x00ff0000UL) >> 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 colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(int i = NUM_LEDS+NUM_LEDS; i > 0; i--) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}
This topic was modified 3 years ago by Anonymous

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2791
 

I've added you video here for future reference, I hope that's OK. (as a new user you cannot yet upload video's - apologies for the inconvenience)

First off, in the original code I count to NUM_LEDS+NUM_LEDS intentionally so it exceeds the length of the LED strip and all LEDs can fade.
(the 3rd line, the for-loop, in the effect code)

Now ... working in reverse would cause some extra issues to look at (like negative led numbers).
So I'd probably keep the original code the same, and add functions that handle the setPixel (setReversePixel) and fadeToBlack (reverseFadeToBlack) in reverse. 
Something like this (untested - I hope I didn't make any typos):

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) ) {
        reverseFadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setReversePixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

void setReversePixel(int Pixel, byte red, byte green, byte blue) {
  int reversePixel = NUM_LEDS-Pixel;
  
  if( (reversePixel>=0) && (reversePixel<NUM_LEDS) ) {
    setPixel(reversePixel, red, green, blue); 
  }
}

void reverseFadeToBlack(int ledNo, byte fadeValue) {
  int reversePixel = NUM_LEDS-ledNo;
  
  if( (reversePixel>=0) && (reversePixel<NUM_LEDS) ) {
    fadeToBlack(reversePixel, fadeValue); 
  }
}

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 & 0x00ff0000UL) >> 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  
}

   
silvaalonso reacted
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
Topic starter  
Posted by: @hans

I've added you video here for future reference, I hope that's OK. (as a new user you cannot yet upload video's - apologies for the inconvenience)

First off, in the original code I count to NUM_LEDS+NUM_LEDS intentionally so it exceeds the length of the LED strip and all LEDs can fade.
(the 3rd line, the for-loop, in the effect code)

Now ... working in reverse would cause some extra issues to look at (like negative led numbers).
So I'd probably keep the original code the same, and add functions that handle the setPixel (setReversePixel) and fadeToBlack (reverseFadeToBlack) in reverse. 
Something like this (untested - I hope I didn't make any typos):

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) ) {
        reverseFadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setReversePixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

void setReversePixel(int Pixel, byte red, byte green, byte blue) {
  int reversePixel = NUM_LEDS-Pixel;
  
  if( (reversePixel>=0) && (reversePixel<NUM_LEDS) ) {
    setPixel(reversePixel, red, green, blue); 
  }
}

void reverseFadeToBlack(int ledNo, byte fadeValue) {
  int reversePixel = NUM_LEDS-ledNo;
  
  if( (reversePixel>=0) && (reversePixel<NUM_LEDS) ) {
    fadeToBlack(reversePixel, fadeValue); 
  }
}

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 & 0x00ff0000UL) >> 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  
}

it worked flawslessly!

 

Thank you very much for the fast response!

 


   
Hans reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2791
 

Awesome - good to hear that worked!  😁  👍 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

BiiiG THX for the "reverse"-Solution!!!


   
Hans reacted
ReplyQuote
Share: