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!



Arduino Meteor rain
 
Share:
Notifications
Clear all

[Solved] Arduino Meteor rain

2 Posts
2 Users
0 Likes
1,742 Views
(@jerryc)
Active Member
Joined: 4 years ago
Posts: 4
Topic starter  

I would like to add meteor rain to start up sequence and have it run twice before continuing the rest of the program. Wound you have an example on what I need to do. Thanks.


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

Hi JerryC,

It depends a little on where you're copying the meteor rain effect from.
I have 2 projects that use it: the original LED Effects project, and the All-in-One LED Effects project.

Meteor rain in the original project (link) is probably the best one to use for your question.

When using the effects in that project, the you could call the meteor rain function twice and then call for another effect.

For example:

void loop() {
  // run meteor rain twice
  meteorRain(0xff,0xff,0xff,10, 64, true, 30);
  meteorRain(0xff,0xff,0xff,10, 64, true, 30);

  // run the rest of the program which can even be other effects if you'd like.
  // 
  //
}





// effects

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 & 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  
}

   
ReplyQuote
Share: