<?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: Running lights with 3 colors (Red, White and Blue!) - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Thu, 12 Nov 2026 13:50:47 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: LED Effects: Running lights with 3 colors (Red, White and Blue!)</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/#post-4670</link>
                        <pubDate>Mon, 06 Feb 2023 12:05:18 +0000</pubDate>
                        <description><![CDATA[Are you thinking of a fixed number of LEDs and colors, that just keep cycling?Meaning:
1. We set all LEDs to the initial colors we like to see.2. We copy the color of the last LED (= LED NU...]]></description>
                        <content:encoded><![CDATA[<p>Are you thinking of a fixed number of LEDs and colors, that just keep cycling?<br />Meaning:</p>
<p>1. We set all LEDs to the initial colors we like to see.<br />2. We copy the color of the last LED (= LED NUM_LEDS-1).<br />3. We shift all LEDs one position (so the last one drops off).<br />4. We copy that last LED color from step 2, to the 1st LED (= LED 0).</p>
<p>If that would be the case, then it would be good to define an array with all the colors.</p>
<p>The simplest, but not very efficient way, would be:</p>
<pre contenteditable="false">leds = CRGB(r,g,b);
leds = CRGB(r,g,b);
...
leds = CRGB(r,g,b);</pre>
<p>Where "CRGB(r,g,b)" is a color of your choosing.<br />Note: keep in mind that the LEDs count from <strong>0</strong> to <strong>NUM_LEDS-1</strong>.<br />Note: Smarter ways would be if we can somehow calculate the colors with a formula, or when chunks repeating patterns can be copied.</p>
<p> </p>
<p>Next we would want a loop that keeps repeating steps 2, 3 and 4.</p>
<p>Something like</p>
<pre contenteditable="false">CRGB LastLED;
...
LastLED = leds;
...</pre>
<p>Shifting can be done with a for-loop, or with the much faster memmove8 function, which looks like this:</p>
<pre contenteditable="false">memmove8( destination, source, amount_of_data );</pre>
<p>so for our LEDs:</p>
<pre contenteditable="false">memmove8( &amp;leds, &amp;leds, (NUM_LEDS-1) * sizeof(CRGB) );</pre>
<p>And of course we need to put that last LED back:</p>
<pre contenteditable="false">leds = LastLED;</pre>
<p>All combined something like this (untested):</p>
<pre contenteditable="false">CRGB LastLED;
...
void loop() 
{

  ...
  while(true)
  {
    LastLED = leds;
    memmove8( &amp;leds, &amp;leds, (NUM_LEDS-1) * sizeof(CRGB) );
    leds = LastLED;
    // possibly a delay here if this goes too fast
  }

}</pre>
<p>  </p>
<p>Hope this helps.</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-running-lights-with-3-colors-red-white-and-blue/#post-4670</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects: Running lights with 3 colors (Red, White and Blue!)</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/#post-4665</link>
                        <pubDate>Mon, 06 Feb 2023 08:38:17 +0000</pubDate>
                        <description><![CDATA[Hello @hans, thank you a lot for your reply! I&#039;m sorry for the imprecise description of my project! But I think you got what I wanted to achieve. My goal is that I want to adjust the code so...]]></description>
                        <content:encoded><![CDATA[Hello @hans, thank you a lot for your reply! I'm sorry for the imprecise description of my project! But I think you got what I wanted to achieve. My goal is that I want to adjust the code so that each color is a segment of pixels and the number of pixels for each segment (color) is defined by a global variable. All colors together should always be 20 pixels. I hope you got a better understanding of what I am trying to do. I already tried to adjust the code by using an Array for the Pixels, but it was not working. Do you have any idea how I could do this?]]></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-running-lights-with-3-colors-red-white-and-blue/#post-4665</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects: Running lights with 3 colors (Red, White and Blue!)</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/#post-4648</link>
                        <pubDate>Fri, 03 Feb 2023 14:02:08 +0000</pubDate>
                        <description><![CDATA[Hi Braincurd!
Thank you for the compliment!Took me a second before I understood what you&#039;re asking (In think).
So you basically want to be able to define colors, and for each color the num...]]></description>
                        <content:encoded><![CDATA[<p>Hi Braincurd!</p>
<p>Thank you for the compliment!<br />Took me a second before I understood what you're asking (In think).</p>
<p>So you basically want to be able to define colors, and for each color the number of LEDs?</p>
<p>In that case, we'd better tart from scratch, as this sketch was not really intended to support this.<br />We'd have to figure a way to capture this in a formula, so we can determine values for (in the original code) b1 and b2, and that based on the number of LEDs that color "segment" may have.</p>
<p>I'd probably go even one step further, and even use a way to shift all LEDs.<br />If we'd go that route, we may even be able to use a predefined array of colors.<br />Not sure how many LEDs you have in mind?</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-running-lights-with-3-colors-red-white-and-blue/#post-4648</guid>
                    </item>
				                    <item>
                        <title>RE: LED Effects: Running lights with 3 colors (Red, White and Blue!)</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/#post-4647</link>
                        <pubDate>Fri, 03 Feb 2023 09:27:15 +0000</pubDate>
                        <description><![CDATA[@hans Hello :) Thank You for all these wonderful effects!
Do you have an idea how I could modify this sketch, so that I have a variable for each color to set the amount of pixles for each c...]]></description>
                        <content:encoded><![CDATA[<p>@hans Hello :) Thank You for all these wonderful effects!</p>
<p>Do you have an idea how I could modify this sketch, so that I have a variable for each color to set the amount of pixles for each color?</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-running-lights-with-3-colors-red-white-and-blue/#post-4647</guid>
                    </item>
				                    <item>
                        <title>LED Effects: Running lights with 3 colors (Red, White and Blue!)</title>
                        <link>https://www.tweaking4all.com/forum/arduino/led-effects-running-lights-with-3-colors-red-white-and-blue/#post-2174</link>
                        <pubDate>Thu, 04 Jun 2020 14:55:58 +0000</pubDate>
                        <description><![CDATA[While tinkering on something similar, I was able to change my code easily to support 3 colors, showing red, white and blue.You can select you own colors of course and the speed.
This sketch...]]></description>
                        <content:encoded><![CDATA[<p>While tinkering on something similar, I was able to change my code easily to support 3 colors, showing red, white and blue.<br />You can select you own colors of course and the speed.</p>
<p>This sketch relies on FastLed.<br />Set the proper NUM_LEDS and the proper PIN used on your Arduino.</p>
<pre>#include "FastLED.h"<br />#define NUM_LEDS <strong>60</strong><br />CRGB leds;<br />#define PIN <strong>6</strong><br /><br />void setup()<br />{<br />  FastLED.addLeds&lt;WS2811, PIN, GRB&gt;(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );<br />}<br /><br />void loop() {<br />  RunningLights(0x00, 0x00, 0xff, // blue<br />                0xff, 0xff, 0xff, // white <br />                0xff, 0x00, 0x00, // red<br />                150); <br />}<br /><br />void RunningLights(byte red1, byte green1, byte blue1, <br />byte red2, byte green2, byte blue2,<br />byte red3, byte green3, byte blue3, int WaveDelay) {<br /><br />float b1 = 0.05; // brightness LEDs 1 and 5<br />float b2 = 0.2; // brightness LEDs 2 and 4<br /><br />int Col1Pos = 0;<br /><br />for(int start=0; start&lt;15; start++) /// "strip" is 10 leds: 2x5 leds<br />{<br />  for (int i=-15; i &lt; NUM_LEDS+15; i=i+15) {<br />    Col1Pos = i+start;<br /><br />    setMyPixel(Col1Pos, b1*red1, b1*green1, b1*blue1); //turn every third pixel on<br />    setMyPixel(Col1Pos+1, b2*red1, b2*green1, b2*blue1);<br />    setMyPixel(Col1Pos+2, red1, green1, blue1);<br />    setMyPixel(Col1Pos+3, b2*red1, b2*green1, b2*blue1);<br />    setMyPixel(Col1Pos+4, b1*red1, b1*green1, b1*blue1);<br /><br />    setMyPixel(Col1Pos+5, b1*red2, b1*green2, b1*blue2); //turn every third pixel on<br />    setMyPixel(Col1Pos+6, b2*red2, b2*green2, b2*blue2);<br />    setMyPixel(Col1Pos+7, red2, green2, blue2);<br />    setMyPixel(Col1Pos+8, b2*red2, b2*green2, b2*blue2);<br />    setMyPixel(Col1Pos+9, b1*red2, b1*green2, b1*blue2);<br /><br />    setMyPixel(Col1Pos+10, b1*red3, b1*green3, b1*blue3); //turn every third pixel on<br />    setMyPixel(Col1Pos+11, b2*red3, b2*green3, b2*blue3);<br />    setMyPixel(Col1Pos+12, red3, green3, blue3);<br />    setMyPixel(Col1Pos+13, b2*red3, b2*green3, b2*blue3); <br />    setMyPixel(Col1Pos+14, b1*red3, b1*green3, b1*blue3);<br />  }<br /><br />  FastLED.show();<br />  delay(WaveDelay);<br />}<br /><br />}<br /><br />void setMyPixel(int Pixel, byte red, byte green, byte blue) {<br />  if( (Pixel&gt;=0) &amp;&amp; (Pixel&lt;=NUM_LEDS) )<br />  {<br />    leds = CRGB( red, green, blue);<br />  }<br />}</pre>
16
<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-running-lights-with-3-colors-red-white-and-blue/#post-2174</guid>
                    </item>
							        </channel>
        </rss>
		