<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									LED Effects - Meteor Rain with user defined background color - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 21 Jul 2026 02:12:32 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: LED Effects - Meteor Rain with user defined background color</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2708</link>
                        <pubDate>Thu, 05 Nov 2020 20:54:30 +0000</pubDate>
                        <description><![CDATA[@hans Works perfectly. THank you!
I made a modification so the meteor go from one side, then comes back from the other. Seems like there is a tiny color glitch after the meteor came back, n...]]></description>
                        <content:encoded><![CDATA[<p>@hans Works perfectly. THank you!</p>
<p>I made a modification so the meteor go from one side, then comes back from the other. Seems like there is a tiny color glitch after the meteor came back, not sure why but it's fine anyway. Here's the code:</p>
<blockquote>
<p>#include "FastLED.h"<br />#define NUM_LEDS 136<br />CRGB leds;<br />#define PIN 6</p>
<p>void setup()<br />{<br />FastLED.addLeds&lt;WS2811, PIN, GRB&gt;(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );<br />}</p>
<p>void loop() <br />{<br />meteorRain(CRGB(0x10,0x18,0x10), CRGB(0xFF,0x11,0x26),10 ,64 ,true, 30);<br />meteorRainReverse(CRGB(0x10,0x18,0x10), CRGB(0xFF,0x11,0x26),10 ,64 ,true, 30);<br />}</p>
<p>void meteorRain(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) <br />{ <br />// set background color<br />fill_solid( leds, NUM_LEDS, ColorBackground );</p>
<p>for(int i = 0; i &lt; NUM_LEDS+NUM_LEDS; i++) <br />{<br />// fade color to background color for all LEDs<br />for(int j=0; j &lt; NUM_LEDS; j++) {<br />if( (!meteorRandomDecay) || (random(10) &gt; 5) ) {<br />leds = fadeTowardColor(leds, ColorBackground, meteorTrailDecay ); <br />}<br />}</p>
<p>// draw meteor<br />for(int j = 0; j &lt; meteorSize; j++) {<br />if( ( i-j &lt; NUM_LEDS) &amp;&amp; (i-j &gt;= 0) ) {<br />leds= ColorMeteor;<br />}<br />}<br /><br />FastLED.show();<br />delay(SpeedDelay);<br />}<br />}</p>
<p>void meteorRainReverse(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) <br />{ <br />// set background color<br />fill_solid( leds, NUM_LEDS, ColorBackground );</p>
<p>for(int i = 0; i &lt; NUM_LEDS+NUM_LEDS; i++) <br />{<br />// fade color to background color for all LEDs<br />for(int j=0; j &lt; NUM_LEDS; j++) {<br />if( (!meteorRandomDecay) || (random(10) &gt; 5) ) {<br />leds = fadeTowardColor(leds, ColorBackground, meteorTrailDecay ); <br />}<br />}</p>
<p>// draw meteor<br />for(int j = 0; j &lt; meteorSize; j++) {<br />if( ( i-j &lt; NUM_LEDS) &amp;&amp; (i-j &gt;= 0) ) {<br />leds= ColorMeteor;<br />}<br />}<br /><br />FastLED.show();<br />delay(SpeedDelay);<br />}<br />}</p>
<p>// Functions from Kriegsman example<br />CRGB fadeTowardColor( CRGB&amp; cur, const CRGB&amp; target, uint8_t amount)<br />{<br />nblendU8TowardU8( cur.red, target.red, amount);<br />nblendU8TowardU8( cur.green, target.green, amount);<br />nblendU8TowardU8( cur.blue, target.blue, amount);<br />return cur;<br />}</p>
<p>// function used by "fadeTowardColor"<br />void nblendU8TowardU8( uint8_t&amp; cur, const uint8_t target, uint8_t amount)<br />{<br />if( cur == target) return;<br /><br />if( cur &lt; target ) {<br />uint8_t delta = target - cur;<br />delta = scale8_video( delta, amount);<br />cur += delta;<br />} else {<br />uint8_t delta = cur - target;<br />delta = scale8_video( delta, amount);<br />cur -= delta;<br />}<br />}</p>
</blockquote>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>TheChug</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2708</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects - Meteor Rain with user defined background color</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2689</link>
                        <pubDate>Tue, 03 Nov 2020 14:19:17 +0000</pubDate>
                        <description><![CDATA[Thanks! Let me know how this works for you 😉 👍]]></description>
                        <content:encoded><![CDATA[<p>Thanks! Let me know how this works for you 😉 👍 </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2689</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects - Meteor Rain with user defined background color</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2688</link>
                        <pubDate>Tue, 03 Nov 2020 14:18:14 +0000</pubDate>
                        <description><![CDATA[Wow man, that&#039;s LEGEND. I&#039;ll test it on my house tonight!]]></description>
                        <content:encoded><![CDATA[<p>Wow man, that's LEGEND. I'll test it on my house tonight!</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>TheChug</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2688</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects - Meteor Rain with user defined background color</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2687</link>
                        <pubDate>Tue, 03 Nov 2020 13:56:55 +0000</pubDate>
                        <description><![CDATA[Here the INO file (in case the code got corrupted in the post).]]></description>
                        <content:encoded><![CDATA[<p>Here the INO file (in case the code got corrupted in the post).</p>
96
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2687</guid>
                    </item>
				                    <item>
                        <title>LED Effects - Meteor Rain with user defined background color</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2686</link>
                        <pubDate>Tue, 03 Nov 2020 13:51:27 +0000</pubDate>
                        <description><![CDATA[Here a modified Meteor Rain code, based on an old request by Trace and more recent by Christian. 
This code is written for an Arduino Uno and FastLED.I moved to FastLED since Trace prefers ...]]></description>
                        <content:encoded><![CDATA[<p>Here a modified Meteor Rain code, based on <a href="https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#comment-422000" target="true">an old request by Trace</a> and <a href="https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#comment-510622" target="true">more recent by Christian</a>. </p>
<p>This code is written for an Arduino Uno and FastLED.<br />I moved to FastLED since Trace prefers this, just like I do, over NeoPixel, and it makes the code a lot shorter.</p>
<p>The idea of this effect is that the user defines a background, for example red, and the user defines the meteor moving over it, for example yellow. <br />In the original Meteor rain we use FadeToBlack, but unfortunately, it only fades to black, and not a user defined color.</p>
<p><span>Do for this to work I needed a new Fade-a-Color-to-Color function.</span><br /><span>I found </span><a href="https://gist.github.com/kriegsman/d0a5ed3c8f38c64adcb4837dafb6e690" target="_blank" rel="noopener">this excellent GitHub code from Kriegsman</a><span>, from which I copied that function.</span><br /><span>I also moved everything over to just FastLED, making the code shorter.</span></p>
<p>The result:</p>
95
<p> </p>
<p>Code combined and tested:</p>
<pre>#include "FastLED.h"
#define NUM_LEDS 60
CRGB leds;
#define PIN 6

void setup()
{
  FastLED.addLeds&lt;WS2811, PIN, GRB&gt;(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() 
{
  meteorRain(CRGB(0x10,0x00,0x00), CRGB(0xff,0xff,0x00),10 ,64 ,true, 30);
} 

void meteorRain(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) 
{  
  // set background color
  fill_solid( leds, NUM_LEDS, ColorBackground );

  for(int i = 0; i &lt; NUM_LEDS+NUM_LEDS; i++) 
  {
    // fade color to background color for all LEDs<br />    for(int j=0; j &lt; NUM_LEDS; j++) {<br />      if( (!meteorRandomDecay) || (random(10) &gt; 5) ) {<br />        leds = fadeTowardColor(leds, ColorBackground, meteorTrailDecay ); <br />      }<br />    }<br /><br />    // draw meteor<br />    for(int j = 0; j &lt; meteorSize; j++) {<br />      if( ( i-j &lt; NUM_LEDS) &amp;&amp; (i-j &gt;= 0) ) {<br />        leds= ColorMeteor;<br />      }<br />    }
   
    FastLED.show();
    delay(SpeedDelay);
  }
}

// Functions from Kriegsman example
CRGB fadeTowardColor( CRGB&amp; cur, const CRGB&amp; target, uint8_t amount)
{
  nblendU8TowardU8( cur.red,   target.red,   amount);
  nblendU8TowardU8( cur.green, target.green, amount);
  nblendU8TowardU8( cur.blue,  target.blue,  amount);
  return cur;
}

// function used by "fadeTowardColor"
void nblendU8TowardU8( uint8_t&amp; cur, const uint8_t target, uint8_t amount)
{
  if( cur == target) return;
  
  if( cur &lt; target ) {
    uint8_t delta = target - cur;
    delta = scale8_video( delta, amount);
    cur += delta;
  } else {
    uint8_t delta = cur - target;
    delta = scale8_video( delta, amount);
    cur -= delta;
  }
}</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-meteor-rain-with-user-defined-background-color/#post-2686</guid>
                    </item>
							        </channel>
        </rss>
		