<?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>
									How do I change color in my code - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Wed, 20 May 2026 07:32:24 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3380</link>
                        <pubDate>Sat, 24 Apr 2021 10:44:12 +0000</pubDate>
                        <description><![CDATA[What kind of error did you get?
As for adapting the code from that video (which looks pretty cool by the way):
You see in the code that Hasitha (the developer) made functions for each of t...]]></description>
                        <content:encoded><![CDATA[<p>What kind of error did you get?</p>
<p>As for adapting the code from that video (which looks pretty cool by the way):</p>
<p>You see in the code that Hasitha (the developer) made functions for each of the effects (at the end of the code).<br />Simply do not call the ones you do not need, and modify the ones you'd like modified.<br />Shouldn't take too much effort.</p>
<p>Note: For reference and convenience, I've uploaded the code that goes with the video ... just incase</p>
192]]></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/how-do-i-change-color-in-my-code/#post-3380</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3377</link>
                        <pubDate>Fri, 23 Apr 2021 21:22:29 +0000</pubDate>
                        <description><![CDATA[@hans
I tried your suggestions but it threw up an error for each.
I have a better suggestion . can the code from video below be modified to just have the right, left and brake effect with ...]]></description>
                        <content:encoded><![CDATA[<p>@hans</p>
<p>I tried your suggestions but it threw up an error for each.</p>
<p>I have a better suggestion . can the code from video below be modified to just have the right, left and brake effect with brake effect of my code ( Leds from out to center and turning off in same way just for the brake mode and not any other combinations. meaning in hazard + brake or brake + left or brake + right the number of leds for brake can stay solid.</p>
<p> </p>
<p>please refer to this video , the code can be downloaded form the description of the video</p>
<p> </p>
<p>https://www.youtube.com/watch?v=-kA0ffAG03A&amp;t=122s</p>
<p> </p>
<p>thank you</p>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>sid</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3377</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3360</link>
                        <pubDate>Thu, 22 Apr 2021 10:01:04 +0000</pubDate>
                        <description><![CDATA[Let me see if I understand this correctly; so the effect should only work for turning left OR turning right?
In that case I&#039;d change this line (in void loop() ):
if( (Stop==HIGH) || (Left=...]]></description>
                        <content:encoded><![CDATA[<p>Let me see if I understand this correctly; so the effect should only work for turning left OR turning right?</p>
<p>In that case I'd change this line (in void loop() ):</p>
<pre contenteditable="false">if( (Stop==HIGH) || (Left==HIGH) || (Right==HIGH))</pre>
<p> </p>
<p>to something like this:</p>
<pre contenteditable="false">if( (Stop==HIGH) || ( (Left==HIGH) &amp;&amp; (Right!=HIGH) ) || ( (Right==HIGH) &amp;&amp; (Left!=HIGH) )</pre>
<p> </p>
<p>So only show the effect when stop is high (since you mentioned that stop should do anything, you may want to remove that), and only when just going LEFT (and not RIGHT), or going RIGHT (and not LEFT)</p>
<p>Without STOP:</p>
<pre contenteditable="false">if( ( (Left==HIGH) &amp;&amp; (Right!=HIGH) ) || ( (Right==HIGH) &amp;&amp; (Left!=HIGH) )</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/how-do-i-change-color-in-my-code/#post-3360</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3359</link>
                        <pubDate>Wed, 21 Apr 2021 22:55:43 +0000</pubDate>
                        <description><![CDATA[@hans
Hello again
I need another favor to ask. I need to make some changes so that when the Hazard light is on ( both left and right turn signals are flashing ) , the LEDs stay off even wh...]]></description>
                        <content:encoded><![CDATA[<p>@hans</p>
<p>Hello again</p>
<p>I need another favor to ask. I need to make some changes so that when the Hazard light is on ( both left and right turn signals are flashing ) , the LEDs stay off even when the brake is on. other words, the turn signal effect should only work when the left or right turn signal is on. brake should not have any effect when either doing turn signal or the hazard</p>
<p>I could not figure out how to make this change so it wont affect other functions of the code.</p>
<p>would you please kindly help me with that?</p>
<p>thanks</p>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>sid</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-3359</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2960</link>
                        <pubDate>Tue, 22 Dec 2020 10:53:12 +0000</pubDate>
                        <description><![CDATA[Awesome! Good to hear that! 👍 
Enjoy the holidays and have a great new year! 😉]]></description>
                        <content:encoded><![CDATA[<p>Awesome! Good to hear that! 👍 </p>
<p>Enjoy the holidays and have a great new year! 😉 </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/how-do-i-change-color-in-my-code/#post-2960</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2957</link>
                        <pubDate>Mon, 21 Dec 2020 20:14:48 +0000</pubDate>
                        <description><![CDATA[@hans Hello Hans,
thank you for taking the time to look at the my code.
I applied your suggestions and it seems to be working as desired.
 
thanks again]]></description>
                        <content:encoded><![CDATA[<p>@hans Hello Hans,</p>
<p>thank you for taking the time to look at the my code.</p>
<p>I applied your suggestions and it seems to be working as desired.</p>
<p> </p>
<p>thanks again</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>saeidans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2957</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2949</link>
                        <pubDate>Sat, 19 Dec 2020 22:52:07 +0000</pubDate>
                        <description><![CDATA[p.s. this is a related post for a blinker in this forum, and the result of that conversation can also be found on GitHub.It is missing the stop/brake though.]]></description>
                        <content:encoded><![CDATA[<p>p.s. this is a <a href="https://www.tweaking4all.com/forum/arduino/running-light-with-push-button/#post-1666" target="true">related post for a blinker</a> in this forum, and the result of that conversation can also be found on <a href="https://github.com/Robiv8/TurnSignal-WS2812B" target="true">GitHub</a>.<br />It is missing the stop/brake though.</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/how-do-i-change-color-in-my-code/#post-2949</guid>
                    </item>
				                    <item>
                        <title>RE: How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2948</link>
                        <pubDate>Sat, 19 Dec 2020 22:45:57 +0000</pubDate>
                        <description><![CDATA[Hi Sid,
welcome to the forum! 😊 
I also notice that you lock &quot;if(Stop==LOW)&quot; inside the IF-loop where you test for Stop==HIGH - so that condition will never be reached (if I&#039;m reading this...]]></description>
                        <content:encoded><![CDATA[<p>Hi Sid,</p>
<p>welcome to the forum! 😊 </p>
<p>I also notice that you lock "if(Stop==LOW)" inside the IF-loop where you test for Stop==HIGH - so that condition will never be reached (if I'm reading this right - note: always a good idea to attach the INO file to your post in the future, but as a new user you will have to post a few legit posts first before you can do that).</p>
<p>So example this part of the code: the bold red code will never be executed, since in this section Stop==HIGH.</p>
<pre>if (Stop == HIGH) {
  for (int i = 0; i &lt;= (NUM_LEDS / 2 - 1); ++i) {
    leds = CRGB(red, green, blue);
    leds = CRGB(red, green, blue);
    delay(SpeedDelay);
    FastLED.show();
  }
 
<strong><span style="color: #ff0000">  if (Stop == LOW) {
    FastLED.clear();
  }</span></strong>
}</pre>
<p>Now you could move that IF outside of that initial IF-loop, but then this would set the LEDs to black each time - not what you had in mind.<br />So to avoid all that, I'd probably modify the colorSwpie function a little bit, since the leds are all turned off when all 3 (left, right, stop) are not HIGH.</p>
<p> </p>
<p>Tip: You can use shorter colors notations, see the <a href="https://github.com/FastLED/FastLED/wiki/Pixel-reference#predefined-colors-list" target="true">FastLED color reference</a> list if you'd like to use those (not required of course, but it does make the code more readable if you use just a few basic colors). For example  <strong>CRGB(0x00,0x00,0x00)</strong> = <strong>CRGB::Black</strong>   and   <strong>CRGB(0xFF,0xFF,0x00)</strong> = <strong>CRGB::Yellow</strong>. 😊 </p>
<p>Also not sure if required, but I think you have to do a FastLED.show() after a FastLED.clear(). I could be wrong though.</p>
<p> </p>
<p>So you could do something like this (I removed the speedDelay since it didn't have much of a purpose there):</p>
<p><strong>!! Don't forget</strong>: <br />You will have to add the beginning of your code (#defines, #include, int's and void setup()) - since this code was a little incomplete, probably because I tried putting it in code format in your post.<br />The bold parts of the code are my changes.</p>
<pre>...<br /><strong>#define BrakeDelay 150</strong><br /><strong>#define BlinkerDelay 60</strong><br />...<br /><br />void loop() {
  Stop = digitalRead(Pin1);
  Left = digitalRead(Pin2);
  Right = digitalRead(Pin3);
   
  <strong>colorWipe(CRGB::Yellow);
  colorWipe(CRGB::Black);</strong>
}

<strong>void colorWipe(CRGB WipeColor) {

  if (Stop == HIGH) // brake - outsides to center
  {
    for (int i = 0; i &lt;= (NUM_LEDS / 2 - 1); ++i) 
    {
      leds = WipeColor;
      leds = WipeColor;
      delay(BrakeDelay);
      FastLED.show();
    }
  } 
  else if (Right == HIGH)  // right turn - right to center
  {
    for (int i = NUM_LEDS / 2; i &lt; NUM_LEDS; i++) 
    {
      leds = WipeColor; // removed the "mirror" leds
      FastLED.show();
      delay(BlinkerDelay); // change the number here to change the speed of the LEDs
    }
  } 
  else if (Left == HIGH) //left turn - left to center
  {
    for (int i = NUM_LEDS / 2 - 1; i &gt;= 0; i--) 
    { 
      leds = WipeColor; // removed the "mirror" leds
      FastLED.show();
      delay(BlinkerDelay); // change the number here to change the speed of the LEDs
    }
  }
  else
  {
    FastLED.clear();
    FastLED.show();
  }
  
}</strong></pre>
<p> </p>
<p>I couldn't resist so I made another modification, so Stop becomes red and Left/Right remains yellow (note: I have not tested this with switches).</p>
<pre>...
#define BrakeDelay 150
#define BlinkerDelay 60
...<br />
void loop() {
  Stop = digitalRead(Pin1);
  Left = digitalRead(Pin2);
  Right = digitalRead(Pin3);

  if( (Stop==HIGH) || (Left==HIGH) || (Right==HIGH))
  {
    if(Stop==HIGH) 
    {
      colorWipe(CRGB::Red);
    }
    else
    {
      colorWipe(CRGB::Yellow);
    }
    
    colorWipe(CRGB::Black);
  }
  else
  {
    FastLED.clear();
    FastLED.show();
  }
}

void colorWipe(CRGB WipeColor) {

  if (Stop == HIGH) // brake - outsides to center
  {
    for (int i = 0; i &lt;= (NUM_LEDS / 2 - 1); ++i) 
    {
      leds = WipeColor;
      leds = WipeColor;
      delay(BrakeDelay);
      FastLED.show();
    }
  } 
  else if (Right == HIGH)  // right turn - right to center
  {
    for (int i = NUM_LEDS / 2; i &lt; NUM_LEDS; i++) 
    {
      leds = WipeColor; 
      FastLED.show();
      delay(BlinkerDelay); 
    }
  } 
  else if (Left == HIGH) //left turn - left to center
  {
    for (int i = NUM_LEDS / 2 - 1; i &gt;= 0; i--) 
    { 
      leds = WipeColor; 
      FastLED.show();
      delay(BlinkerDelay); 
    }
  }
}</pre>
<p> </p>
<p>And another note: this all can be done more efficient, but I think this should do what you want it to do, 😊 </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/how-do-i-change-color-in-my-code/#post-2948</guid>
                    </item>
				                    <item>
                        <title>How do I change color in my code</title>
                        <link>https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2944</link>
                        <pubDate>Sat, 19 Dec 2020 17:34:25 +0000</pubDate>
                        <description><![CDATA[Hi,
I need to be able to use different color in following code for each input, Red for Brake and Yellow for turn signals.
The current code changes color for all inputs. I appreciate your h...]]></description>
                        <content:encoded><![CDATA[<p>Hi,</p>
<p>I need to be able to use different color in following code for each input, Red for Brake and Yellow for turn signals.</p>
<p>The current code changes color for all inputs. I appreciate your help in advance.</p>
<p>thanks</p>
<p> </p>
<pre>int Pin2 = 9; // pin 9 is used for Left turn
int Left;
int Pin3 = 8; // pin 8 is used for Right turn 
int Right;
CRGB leds;

void setup() {
  FastLED.addLeds &lt; WS2812, PIN, GRB &gt; (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  pinMode(Pin1, INPUT);
  pinMode(Pin2, INPUT);
  pinMode(Pin3, INPUT);

}
void loop() {

  Stop = digitalRead(Pin1);
  Left = digitalRead(Pin2);
  Right = digitalRead(Pin3);
  colorWipe(0xff, 0xff, 0x00, 150);
  colorWipe(0x00, 0x00, 0x00, 150);
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {

  if (Stop == HIGH) {

    for (int i = 0; i &lt;= (NUM_LEDS / 2 - 1); ++i) {
      leds = CRGB(red, green, blue);
      leds = CRGB(red, green, blue);
      delay(SpeedDelay);
      FastLED.show();
    }

    if (Stop == LOW) {
      FastLED.clear();
    }

  } else if (Right == HIGH) {
    for (int i = NUM_LEDS / 2; i &lt; NUM_LEDS; i++) {
      leds = CRGB(red, green, blue); // removed the "mirror" leds
      FastLED.show();
      delay(60); // chnage the number here to chnage the speed of the LEDs
    }

    if (Right == LOW) {
      FastLED.clear();

    }

  } else if (Left == HIGH) {
    for (int i = NUM_LEDS / 2 - 1; i &gt;= 0; i--) { //left turn
      leds = CRGB(red, green, blue); // removed the "mirror" leds
      FastLED.show();
      delay(60); // chnage the number here to chnage the speed of the LEDs
    }

    if (Left == LOW) {
      FastLED.clear();

    }
  }
}</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>sid</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/how-do-i-change-color-in-my-code/#post-2944</guid>
                    </item>
							        </channel>
        </rss>
		