<?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 - Fade out on rainbow cycle - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Wed, 20 May 2026 07:12:14 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: LED effects - Fade out on rainbow cycle</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-4716</link>
                        <pubDate>Sat, 18 Feb 2023 05:11:15 +0000</pubDate>
                        <description><![CDATA[Many many THANKS! for sharing this Sketch!!!! Now i have my RainbowSparkle Code ♥]]></description>
                        <content:encoded><![CDATA[<p>Many many THANKS! for sharing this Sketch!!!! Now i have my RainbowSparkle Code ♥</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-4716</guid>
                    </item>
				                    <item>
                        <title>RE: LED effects - Fade out on rainbow cycle</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2859</link>
                        <pubDate>Sun, 29 Nov 2020 14:08:43 +0000</pubDate>
                        <description><![CDATA[Hi Arnaud!
Awesome! Glad to hear this did the trick and thank you for posting the full code! 😊]]></description>
                        <content:encoded><![CDATA[<p>Hi Arnaud!</p>
<p>Awesome! Glad to hear this did the trick and thank you for posting the full code! 😊</p>
<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-fade-out-on-rainbow-cycle/#post-2859</guid>
                    </item>
				                    <item>
                        <title>RE: LED effects - Fade out on rainbow cycle</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2858</link>
                        <pubDate>Sun, 29 Nov 2020 13:49:54 +0000</pubDate>
                        <description><![CDATA[Hi Hans,
Thank you very much, it&#039;s exactly what I need and your explanations are very clear.I replaced 20 times by 53 times and 64 by 26 to have 10% and a slower fade to black. Like you I u...]]></description>
                        <content:encoded><![CDATA[<p>Hi Hans,</p>
<p>Thank you very much, it's exactly what I need and your explanations are very clear.<br />I replaced 20 times by 53 times and 64 by 26 to have 10% and a slower fade to black. Like you I used a spreadsheet.</p>
<p>Hereafter there is the working code.<br />Inside there are the fire effect and the theater effect that I keep to use after on a 200 LED strip.</p>
<pre>// Code source: Hans Luijten<br />// Website: https://www.tweaking4all.com<br /><br />#include &lt;Adafruit_NeoPixel.h&gt;<br />#include &lt;EEPROM.h&gt;<br />//#include &lt;FastLED.h&gt; *Not used for the moment<br /><br />#define NUM_LEDS 100 <br />#define PIN 6 <br />Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);<br /><br /><br />void setup()<br />{<br />strip.begin();<br />strip.show(); // Initialize all pixels to 'off'<br />}<br /><br />// *** REPLACE FROM HERE ***<br />void loop() {<br /><br />int i;<br />int j;<br />int k;<br /><br />{<br />fadeInRainbow(5);<br />}<br /><br />for(i=0; i&lt;random (5,15); i++) { <br />rainbowCycleWithSparkle(50,20);<br />}<br /><br />{<br />fadeOutRainbow(20);<br />}<br /><br />for(j=0; j&lt;random (0,4); j++) { <br />meteorRain(0xff,0xff,0xff,10, 64, true, 30);<br />}<br /><br />{ <br />meteorRainTransition(0xff,0xff,0xff,10, 64, true, 30);<br />}<br /><br />{<br />colorWipeReversed(0xff,0xff,0xff, 10);<br />// colorWipeReversed(0x00,0x00,0x00, 20);<br />}<br /><br />for(k=0; k&lt;random (3000,20000); k++) { <br />Sparkle(0xff, 0xff, 0xff, 0);<br />}<br /><br />}<br /><br /><br />// *************************<br />// ** LEDEffect Functions **<br />// *************************<br /><br /><br />//fadeInRainbow<br />void fadeInRainbow(int SpeedDelay) {<br /><br />byte *c;<br />uint16_t i, j;<br />for(j = 0; j &lt; 256; j=j+1) {<br />for(i=0; i&lt; NUM_LEDS; i++) {<br />c=Wheel((i * 256 / NUM_LEDS) &amp; 255);<br />setPixel(i, *c*(j/256.0), *(c+1)*(j/256.0), *(c+2)*(j/256.0));<br />}<br /><br />showStrip();<br />delay(SpeedDelay);<br />}<br />}<br /><br />//Sparkle<br />void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {<br />int Pixel = random(NUM_LEDS);<br />setPixel(Pixel,red,green,blue);<br />showStrip();<br />delay(SpeedDelay);<br />setPixel(Pixel,0,0,0);<br />}<br /><br />//colorWipeReversed<br />void colorWipeReversed(byte red, byte green, byte blue, int SpeedDelay) {<br />for(uint16_t i=NUM_LEDS; i&gt;0; i--) {<br />setPixel(i, red, green, blue);<br />showStrip();<br />delay(SpeedDelay);<br />}<br />}<br /><br />//RainbowCycleWithSparkle<br />void rainbowCycleWithSparkle(int SparkleDelay, int SpeedDelay) {<br />byte *c;<br />uint16_t i, j;<br /><br />for(j=0; j&lt;256; j++) { <br />for(i=0; i&lt; NUM_LEDS; i++) {<br />c=Wheel(((i * 256 / NUM_LEDS) + j) &amp; 255);<br />setPixel(i, *c, *(c+1), *(c+2));<br />}<br />showStrip();<br />delay(SpeedDelay);<br />int Pixel = random(NUM_LEDS);<br />setPixel(Pixel,0xff,0xff,0xff);<br />showStrip();<br />delay(SparkleDelay);<br />}<br />}<br /><br />// used by rainbowCycleWithSparkle <br />byte * Wheel(byte WheelPos) {<br />static byte c;<br /><br />if(WheelPos &lt; 85) {<br />c=WheelPos * 3;<br />c=255 - WheelPos * 3;<br />c=0;<br />} else if(WheelPos &lt; 170) {<br />WheelPos -= 85;<br />c=255 - WheelPos * 3;<br />c=0;<br />c=WheelPos * 3;<br />} else {<br />WheelPos -= 170;<br />c=0;<br />c=WheelPos * 3;<br />c=255 - WheelPos * 3;<br />}<br /><br />return c;<br />}<br /><br />//fadeOutRainbow<br />void fadeOutRainbow(int SpeedDelay) {<br /><br />// 53 times reduce the color brightness by 10%, reaching close to zero (black)<br />for(int j=1; j&lt;53; j++) { <br />for(int i=0; i&lt; NUM_LEDS; i++) {<br />fadeToBlack(i, 26); // 26 / 256 = 10% brightness reduction<br />}<br /><br />showStrip();<br />delay(SpeedDelay);<br />}<br />}<br /><br />//theaterChaseRainbow<br />// not used for the moment<br />void theaterChaseRainbow(int SpeedDelay) {<br />byte *c;<br /><br />for (int j=0; j &lt; 256; j++) { // cycle all 256 colors in the wheel<br />for (int q=0; q &lt; 3; q++) {<br />for (int i=0; i &lt; NUM_LEDS; i=i+3) {<br />c = Wheel( (i+j) % 255);<br />setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on<br />}<br />showStrip();<br /><br />delay(SpeedDelay);<br /><br />for (int i=0; i &lt; NUM_LEDS; i=i+3) {<br />setPixel(i+q, 0,0,0); //turn every third pixel off<br />}<br />}<br />}<br />}<br /><br />//Fire<br />// not used for the moment<br />void Fire(int Cooling, int Sparking, int SpeedDelay) {<br />static byte heat;<br />int cooldown;<br /><br />// Step 1. Cool down every cell a little<br />for( int i = 0; i &lt; NUM_LEDS; i++) {<br />cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);<br /><br />if(cooldown&gt;heat) {<br />heat=0;<br />} else {<br />heat=heat-cooldown;<br />}<br />}<br /><br />// Step 2. Heat from each cell drifts 'up' and diffuses a little<br />for( int k= NUM_LEDS - 1; k &gt;= 2; k--) {<br />heat = (heat + heat + heat) / 3;<br />}<br /><br />// Step 3. Randomly ignite new 'sparks' near the bottom<br />if( random(255) &lt; Sparking ) {<br />int y = random(7);<br />heat = heat + random(160,255);<br />//heat = random(160,255);<br />}<br /><br />// Step 4. Convert heat to LED colors<br />for( int j = 0; j &lt; NUM_LEDS; j++) {<br />setPixelHeatColor(j, heat );<br />}<br /><br />showStrip();<br />delay(SpeedDelay);<br />}<br /><br />// used by Fire<br />void setPixelHeatColor (int Pixel, byte temperature) {<br />// Scale 'heat' down from 0-255 to 0-191<br />byte t192 = round((temperature/255.0)*191);<br /><br />// calculate ramp up from<br />byte heatramp = t192 &amp; 0x3F; // 0..63<br />heatramp &lt;&lt;= 2; // scale up to 0..252<br /><br />// figure out which third of the spectrum we're in:<br />if( t192 &gt; 0x80) { // hottest<br />setPixel(Pixel, 255, 255, heatramp);<br />} else if( t192 &gt; 0x40 ) { // middle<br />setPixel(Pixel, 255, heatramp, 0);<br />} else { // coolest<br />setPixel(Pixel, heatramp, 0, 0);<br />}<br />}<br /><br />//meteorRain<br />void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) { <br />//setAll(0,0,0);<br /><br />for(int i = 0; i &lt; NUM_LEDS+NUM_LEDS; i++) {<br /><br /><br />// fade brightness all LEDs one step<br />for(int j=0; j&lt;NUM_LEDS; j++) {<br />if( (!meteorRandomDecay) || (random(10)&gt;5) ) {<br />fadeToBlack(j, 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 />setPixel(i-j, red, green, blue);<br />} <br />}<br /><br />showStrip();<br />delay(SpeedDelay);<br />}<br />}<br /><br />//meteorRainTransition<br />void meteorRainTransition(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) { <br />setAll(0,0,0);<br /><br />// old: <br />// for(int i = 0; i &lt; NUM_LEDS+NUM_LEDS; i++) {<br /><br />// new:<br />for(int i = 0; i &lt; NUM_LEDS; i++) {<br /><br />// fade brightness all LEDs one step<br />for(int j=0; j&lt;NUM_LEDS; j++) {<br />if( (!meteorRandomDecay) || (random(10)&gt;5) ) {<br />fadeToBlack(j, 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 />setPixel(i-j, red, green, blue);<br />}<br />}<br /><br />showStrip();<br />delay(SpeedDelay);<br />}<br />}<br /><br />// used by meteorRain<br />void fadeToBlack(int ledNo, byte fadeValue) {<br />#ifdef ADAFRUIT_NEOPIXEL_H <br />// NeoPixel<br />uint32_t oldColor;<br />uint8_t r, g, b;<br />int value;<br /><br />oldColor = strip.getPixelColor(ledNo);<br />r = (oldColor &amp; 0x00ff0000UL) &gt;&gt; 16;<br />g = (oldColor &amp; 0x0000ff00UL) &gt;&gt; 8;<br />b = (oldColor &amp; 0x000000ffUL);<br /><br />r=(r&lt;=10)? 0 : (int) r-(r*fadeValue/256);<br />g=(g&lt;=10)? 0 : (int) g-(g*fadeValue/256);<br />b=(b&lt;=10)? 0 : (int) b-(b*fadeValue/256);<br /><br />strip.setPixelColor(ledNo, r,g,b);<br />#endif<br />#ifndef ADAFRUIT_NEOPIXEL_H<br />// FastLED<br />leds.fadeToBlackBy( fadeValue );<br />#endif <br />}<br /><br /><br />// *** REPLACE TO HERE ***<br /><br /><br /><br /><br />// ***************************************<br />// ** FastLed/NeoPixel Common Functions **<br />// ***************************************<br /><br />// Apply LED color changes<br />void showStrip() {<br />#ifdef ADAFRUIT_NEOPIXEL_H <br />// NeoPixel<br />strip.show();<br />#endif<br />#ifndef ADAFRUIT_NEOPIXEL_H<br />// FastLED<br />FastLED.show();<br />#endif<br />}<br /><br />// Set a LED color (not yet visible)<br />void setPixel(int Pixel, byte red, byte green, byte blue) {<br />#ifdef ADAFRUIT_NEOPIXEL_H <br />// NeoPixel<br />strip.setPixelColor(Pixel, strip.Color(red, green, blue));<br />#endif<br />#ifndef ADAFRUIT_NEOPIXEL_H <br />// FastLED<br />leds.r = red;<br />leds.g = green;<br />leds.b = blue;<br />#endif<br />}<br /><br />// Set all LEDs to a given color and apply it (visible)<br />void setAll(byte red, byte green, byte blue) {<br />for(int i = 0; i &lt; NUM_LEDS; i++ ) {<br />setPixel(i, red, green, blue); <br />}<br />showStrip();<br />}</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>arnaud</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2858</guid>
                    </item>
				                    <item>
                        <title>RE: LED effects - Fade out on rainbow cycle</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2857</link>
                        <pubDate>Sun, 29 Nov 2020 11:13:59 +0000</pubDate>
                        <description><![CDATA[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&#039;ve done! 👍 Would you mind sharing the full...]]></description>
                        <content:encoded><![CDATA[<p>Thanks Arnaud for taking the time and effort to post this in the forum - it is much appreciated 😊 </p>
<p>Thanks for the very cool video! I like what you've done! 👍 <br />Would you mind sharing the full code once we have it all working?</p>
<p>I think I may have misunderstood your earlier question, so let's try again ...</p>
<p>We probably should consider using the <strong>fadeToBlack</strong> function.<br />You can use the function of my project, or the FastLED build-in function.<br />(I prefer the FastLED library, so if you're going that route, we can eventually cleanup the code and remove the code for NeoPixel)</p>
<p>So this could look something like this:</p>
<pre>void fadeOutRainbow(int SpeedDelay) {<br /><br />  // 20 times reduce the color brightness by 25%, reaching close to zero (black)<br />  for(int j=1; j&lt;<span style="color: #0000ff"><strong>20</strong></span>; j++) { <br />    for(int i=0; i&lt; NUM_LEDS; i++) {<br />      <span>fadeToBlack</span>(i, <span style="color: #ff0000"><strong>64</strong></span>);<br />    }<br />  <br />    showStrip();<br />    delay(SpeedDelay);<br />  }<br />}</pre>
<p>Now I haven't tested this code, and there are 2 point to pay attention to;</p>
<p>In the for-j loop, I've used the random value of <span style="color: #0000ff"><strong>20</strong></span>.</p>
<p>In the for-i loop I do a fadeToBlack for all LEDs by <span style="color: #ff0000"><strong>64</strong></span>, which translates to a <span style="color: #ff0000"><strong>64</strong></span>/256 = <span style="color: #008000"><strong>25%</strong></span> brightness reduction.<br />So in each step, the current led value will be reduced by<span style="color: #008000"><strong> 25%</strong></span>.</p>
<p>So <span style="color: #0000ff"><strong>20</strong></span> times a <span style="color: #008000"><strong>25%</strong></span> reduction, should get a 255 value all the way down to about 1 (which is pretty much "off").<br />If you really want to absolutely go to zero then you''l need up to <span style="color: #0000ff"><strong>38</strong></span> steps.<br />(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%)</p>
<p>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.</p>
<p>You'll have to experiment a little to see what values work best for your setup.</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-fade-out-on-rainbow-cycle/#post-2857</guid>
                    </item>
				                    <item>
                        <title>LED effects - Fade out on rainbow cycle</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2856</link>
                        <pubDate>Sat, 28 Nov 2020 16:23:32 +0000</pubDate>
                        <description><![CDATA[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() ...]]></description>
                        <content:encoded><![CDATA[<p>Hello,</p>
<p>As I explained <a href="https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#comment-517447" target="true">it </a>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.</p>
<p>I tested with a FastLED.setBrightness() and with a strip.setBrightness(), unfortunately in the both cases the led strip freezes.</p>
<p>I tried the code hereafter, it works to fade in not to fade out.<br />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. </p>
<pre>//fadeInRainbow<br />void fadeInRainbow(int SpeedDelay) {<br /><br />  byte *c;<br />  uint16_t i, j;<br />  for(j = 0; j &lt; 256; j=j+1) {<br />    for(i=0; i&lt; NUM_LEDS; i++) {<br />      c=Wheel((i * 256 / NUM_LEDS) &amp; 255);<br />      setPixel(i, *c*(j/256.0), *(c+1)*(j/256.0), *(c+2)*(j/256.0));<br />    }<br />  <br />    showStrip();<br />    delay(SpeedDelay);<br />  }<br />}<br /><br />//fadeOutRainbow<br />//WORK IN  PROGRESS<br />void fadeOutRainbow(int SpeedDelay) {<br /><br />  byte *c;<br />  uint16_t i, j;<br />  for(j = 255; j &gt;= 0; j=j-2) {<br />    for(i=0; i&lt; NUM_LEDS; i++) {<br />      c=Wheel((i * 256 / NUM_LEDS) &amp; 255);<br />      setPixel(i, *c*(j/256.0), *(c+1)*(j/256.0), *(c+2)*(j/256.0));<br />    }<br />  <br />    showStrip();<br />    delay(SpeedDelay);<br />  }<br />}</pre>
<p> </p>
<p>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)<br />But it's not a fade out.</p>
<p> </p>
<p>Unfortunately I forgot to film the version of the code above.</p>
<p>https://youtu.be/vKkichWFwK8</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>arnaud</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/led-effects-fade-out-on-rainbow-cycle/#post-2856</guid>
                    </item>
							        </channel>
        </rss>
		