<?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>
									Fade one color to another color Wemos / NodeMCU - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 17 Mar 2026 00:42:54 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4832</link>
                        <pubDate>Tue, 28 Mar 2023 14:27:57 +0000</pubDate>
                        <description><![CDATA[Thank you for spending so much time trying to solve my annoying problem.
Here is a stripped version of my code. The 2 functions fadeTo and fadeTo2 are working well without WiFi.
When I WiF...]]></description>
                        <content:encoded><![CDATA[<p>Thank you for spending so much time trying to solve my annoying problem.</p>
<p>Here is a stripped version of my code. The 2 functions fadeTo and fadeTo2 are working well without WiFi.</p>
<p>When I WiFi.begin() is enabled the flickering begins.</p>
<p> </p>
<pre contenteditable="false">#include &lt;ESP8266WiFi.h&gt;
#include &lt;PubSubClient.h&gt;
#include &lt;FastLED.h&gt;

IPAddress ip(192, 168, 0, 139);
/*
Gateway
Subnet
DNS
*/

bool updateFadeColors1 = false;
bool updateFadeColors2 = false;

#define NUM_LEDS 60
#define DATA_PIN 2              // 2 er D4 på NodeMCU

byte fadeRed = 255;
byte fadeGreen = 0;
byte fadeBlue = 0;
byte fadeRed2 = 0;
byte fadeGreen2 = 255;
byte fadeBlue2 = 0;
byte fadeAmount = 1;
byte fadeDelay = 100;

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  Serial.begin(115200);
  FastLED.addLeds&lt;WS2812B, DATA_PIN, GRB&gt;(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //Typical8mmPixel); // ( TypicalSMD5050 );
  
  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
 
  if (!client.connected()) {
    reconnect();
  }
  
  setBright(brightness);
  setAll(0,0,255);
  delay(3000);
}

/********************************** START SETUP WIFI*****************************************/
void setup_wifi() {
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.hostname(deviceName);
  WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet, dns);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }

  if (WiFi.status() != WL_CONNECTED) {
    delay(1);
    Serial.print("WIFI Disconnected. Attempting reconnection.");
    setup_wifi();
    return;
  }

  client.loop();
  
  // Set true in callback split function
  if (updateFadeColors1 == true) {
    fadeTo(fadeRed, fadeGreen, fadeBlue, fadeDelay, fadeAmount);
  } else if (updateFadeColors2 == true) {
    fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
  }
}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    
    if (client.connect(deviceName, mqtt_username, mqtt_password)) {
      Serial.println("connected");
      di = "modelbane/neopixels/" + neoName;
      di.toCharArray(diSubscribe, 60);
      
      client.subscribe(diSubscribe);
      delay(5000);
    }
  }
}
void callback(char* topic, byte* payload, unsigned int length) {
  // Split received mqtt msg
}

// Helper function that blends one uint8_t toward another by a given amount
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;
  }
}

CRGB fadeOneColor( 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;
}

void fadeTowardColor( CRGB* L, uint16_t N, const CRGB&amp; bgColor, uint8_t fadeAmount)
{
  fadeOneColor( L, bgColor, fadeAmount); // first LED - calc new color
  if ((bgColor == L)) {
    updateFadeColors1 = false;
  }

  for( uint16_t i = 0; i &lt; N; i++) {
     L = L; // copy color from first LED
  }
}

void fadeTowardColor2( CRGB* L, uint16_t N, const CRGB&amp; bgColor, const CRGB&amp; bgColor2, uint8_t fadeAmount)
{
  fadeOneColor( L, bgColor, fadeAmount); // Calc new color first LED
  fadeOneColor( L, bgColor2, fadeAmount); // and second LED

  if ((bgColor == L) &amp;&amp; (bgColor2 == L)) {
    updateFadeColors2 = false;
  }
  
  for( uint16_t i = 0; i &lt; N; i++) {
    if ((i % 2) == 0) {
      L = L;  // copy 1st LED color
    } else {
      L = L; // copy seconde LED color
    }
  } 
}

void fadeTo(byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) {       //byte red, byte green, byte blue, byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) {
  // Syntax: toRed, toGreen, toBlue, fade delay, how much to fade)
    
  CRGB bgColor(toRed, toGreen , toBlue);
  fadeTowardColor( leds, NUM_LEDS, bgColor, fadeAmount);

  FastLED.show();
  FastLED.delay(fadeDelay);  
}

void fadeTo2(byte toRed, byte toGreen, byte toBlue, byte toRed2, byte toGreen2, byte toBlue2, int fadeDelay, byte fadeAmount) {       //byte red, byte green, byte blue, byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) {
  // Syntax: toRed, toGreen, toBlue, toRed2, toGreen2, toBlue2, fade delay, how much to fade)
    
  CRGB bgColor(toRed, toGreen , toBlue);
  CRGB bgColor2(toRed2, toGreen2, toBlue2);
  fadeTowardColor2( leds, NUM_LEDS, bgColor, bgColor2, fadeAmount);

  FastLED.show();
  FastLED.delay(fadeDelay);  
}</pre>]]></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/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4832</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4830</link>
                        <pubDate>Tue, 28 Mar 2023 11:40:43 +0000</pubDate>
                        <description><![CDATA[Well, you pinned it down to WiFi interfering.
Kind-a odd though ... I have a very large sketch with a lot of effects on it, which I control over WiFi.I run that sketch on a ESP8266, just li...]]></description>
                        <content:encoded><![CDATA[<p>Well, you pinned it down to WiFi interfering.</p>
<p>Kind-a odd though ... <br />I have a very large sketch with a lot of effects on it, which I control over WiFi.<br />I run that sketch on a ESP8266, just like your Wemos D1, yet not a single effect flickers.</p>
<p>Can you post the bare minimum code with an effect that flickers and WiFi enabled?<br />My gut tells me that something is triggering an interrupt - just cannot find anything in the code sniplets you have posted before.</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/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4830</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4829</link>
                        <pubDate>Mon, 27 Mar 2023 16:45:25 +0000</pubDate>
                        <description><![CDATA[@hans
Unfortunately, it didn’t help.]]></description>
                        <content:encoded><![CDATA[@hans
<p>Unfortunately, it didn’t help.</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/fade-one-color-to-another-color-wemos-nodemcu/paged/2/#post-4829</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4828</link>
                        <pubDate>Mon, 27 Mar 2023 13:59:51 +0000</pubDate>
                        <description><![CDATA[@henrikl2000 Sounds like the WiFi is triggering an interrupt that interferes somehow with FastLED or one of &quot;our&quot; functions.
Really not having tested any of this, maybe replace WIFI_NONE_SL...]]></description>
                        <content:encoded><![CDATA[<p>@henrikl2000 Sounds like the WiFi is triggering an interrupt that interferes somehow with FastLED or one of "our" functions.</p>
<p>Really not having tested any of this, maybe replace <strong>WIFI_NONE_SLEEP</strong> with <span style="color: #ff0000"><strong>WIFI_LIGHT_SLEEP</strong></span> - just to see what happens. Wifi should remain connected, but I would assume the polling of WiFi is brought down a notch. (I could be totally guessing this wrong of course - but testing won't hurt.</p>
<pre contenteditable="false">WiFi.setSleepMode(WIFI_LIGHT_SLEEP); </pre>
<p> Let us know if that made a difference. 😊 </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/fade-one-color-to-another-color-wemos-nodemcu/#post-4828</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4821</link>
                        <pubDate>Sun, 26 Mar 2023 13:51:18 +0000</pubDate>
                        <description><![CDATA[After some testing stripping the code to the bare minimum it works without flicker. As soon as I add the WiFi part setup_wifi(); it starts to flicker again. I tried the meteorRain also (whic...]]></description>
                        <content:encoded><![CDATA[<p>After some testing stripping the code to the bare minimum it works without flicker. As soon as I add the WiFi part setup_wifi(); it starts to flicker again. I tried the meteorRain also (which I by way requested a couple of years ago). With the WiFi the meteorRain also flickers.</p>
<p> </p>
<pre contenteditable="false">void setup_wifi() {
  WiFi.hostname(deviceName);
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet, dns);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}</pre>]]></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/fade-one-color-to-another-color-wemos-nodemcu/#post-4821</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4811</link>
                        <pubDate>Sat, 25 Mar 2023 15:14:39 +0000</pubDate>
                        <description><![CDATA[So when can both updateFadeColors1 and updateFadeColors2 be true at the same time?(I would not expect that)
If none or only one can be true, then maybe rewrite this ...
  if (updateFadeCol...]]></description>
                        <content:encoded><![CDATA[<p>So when can both updateFadeColors1 and updateFadeColors2 be true at the same time?<br />(I would not expect that)</p>
<p>If none or only one can be true, then maybe rewrite this ...</p>
<pre contenteditable="false">  if (updateFadeColors1 == true) {
    fadeTo(fadeRed, fadeGreen, fadeBlue, fadeDelay, fadeAmount);
  }

  if (updateFadeColors2 == true) {
    fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
  }</pre>
<p>... to a more correct;</p>
<pre contenteditable="false">  if (updateFadeColors1 == true) {
    fadeTo(fadeRed, fadeGreen, fadeBlue, fadeDelay, fadeAmount);
  } else if (updateFadeColors2 == true) {
    fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
  }</pre>
<p>(Ditto for the other if-then loop)</p>
<p> </p>
<p>It will not fix any problems, its just more correct unless both can be true at the same time of course.</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/fade-one-color-to-another-color-wemos-nodemcu/#post-4811</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4810</link>
                        <pubDate>Fri, 24 Mar 2023 17:20:22 +0000</pubDate>
                        <description><![CDATA[When a new mqtt message arrives
    if (msg.startsWith(&quot;F1C&quot;)) {       
      splitNeoMsgFade1Color(msg);
    } else if (msg.startsWith(&quot;F2C&quot;)) {
      splitNeoMsgFade2Color(msg);
    }...]]></description>
                        <content:encoded><![CDATA[<p>When a new mqtt message arrives<br /><br /></p>
<pre contenteditable="false">    if (msg.startsWith("F1C")) {       
      splitNeoMsgFade1Color(msg);
    } else if (msg.startsWith("F2C")) {
      splitNeoMsgFade2Color(msg);
    }</pre>
<p> </p>
<pre contenteditable="false">void splitNeoMsgFade1Color(String Val)
{
  if (Val.length() &gt; 0) {
    // ************* Split function *************
    // Syntax for sending : "red, green, blue, brightness, fade delay, fade amount" (255,0,0,64,100,5)    
    Val.replace("F1C","");
    
    int idxRed = Val.indexOf(',');
    int idxGreen = Val.indexOf(',', idxRed + 1);
    int idxBlue = Val.indexOf(',', idxGreen + 1);
    int idxBright = Val.indexOf(',', idxBlue + 1);
    int idxFadeDelay = Val.indexOf(',', idxBright +1);
    int idxFadeAmount = Val.indexOf(',', idxFadeDelay + 1);
    
    String r = Val.substring(0, idxRed); // Start, længde
    String g = Val.substring(idxRed + 1, idxGreen);
    String b = Val.substring(idxGreen + 1, idxBlue);
    String bright = Val.substring(idxBlue + 1, idxBright);
    String fDelay = Val.substring(idxBright + 1, idxFadeDelay);
    String fAmount = Val.substring(idxFadeDelay + 1, idxFadeAmount);
    
    fadeRed = r.toInt();
    fadeGreen = g.toInt();
    fadeBlue = b.toInt();
    brightness = bright.toInt();
    fadeDelay = fDelay.toInt();
    fadeAmount = fAmount.toInt();
    
    updateFadeColors1 = true;
    brigtnessUpdated = false;
    Val = "";
  }
</pre>
<p>As you can see in the loop only if updateFadeColors1 or updateFadeColors2 is true the fade should begin.</p>
<p>When the fade is done the updateFadeColors1 /  updateFadeColors2 should be set false</p>
<p>I hope this helps to clarify the 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/fade-one-color-to-another-color-wemos-nodemcu/#post-4810</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4809</link>
                        <pubDate>Fri, 24 Mar 2023 14:35:09 +0000</pubDate>
                        <description><![CDATA[Cleaning up code (naming, indentation, etc), and testing the bare minimum (making sure a specific function actually works), is something I do quite often myself as well. It just makes it eas...]]></description>
                        <content:encoded><![CDATA[<p>Cleaning up code (naming, indentation, etc), and testing the bare minimum (making sure a specific function actually works), is something I do quite often myself as well. It just makes it easier to read (cleaning up code) and easier to debug issues.</p>
<p>As for time, and this happens to all of us; <br />The biggest issue is how much time it takes to read and decipher source codes that has been posted. <br />Besides that, sometimes the question or explanation is not entirely clear to me. 😜 <br />(same goes for me as well when I post a question myself haha)</p>
<p>Sending the entire project is probably not going to help, in fact it will makes it even harder to go through and find the details.</p>
<p>Coming back to your code, I'm not sure what is going on in your void loop().</p>
<p>This part:</p>
<pre contenteditable="false">void loop() {
  if (update1Color == true) {
    setBright(brightness);
    setAll(colorRed, colorGreen, colorBlue);
  }
  if (update2Color == true) {
    setBright(brightness);
    set2Color(colorRed, colorGreen, colorBlue, colorRed2, colorGreen2, colorBlue2);
  }
  if (updateFadeColors1 == true) {
    fadeTo(fadeRed, fadeGreen, fadeBlue, fadeDelay, fadeAmount);
  }

  if (updateFadeColors2 == true) {
    fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
  }
  
  // 1 farve
  if ((leds.r == fadeRed) &amp;&amp; (leds.g == fadeGreen) &amp;&amp; (leds.b == fadeBlue)) {
    updateFadeColors1 = false;
  }
  
  // 2 farver
  if ((leds.r == fadeRed) &amp;&amp; (leds.g == fadeGreen) &amp;&amp; (leds.b == fadeBlue) &amp;&amp; (leds.r == fadeRed2) &amp;&amp; (leds.g == fadeGreen2) &amp;&amp; (leds.b == fadeBlue2)) {
    updateFadeColors2 = false;
  }
}</pre>
<p>Where are update1Color and update2Color set? Are they always true? Both of them?<br />Or are they mutual exclusive (I would guess so?)?<br />How does that correlate with updateFadeColors1 and 2? </p>
<p>Maybe we can look at that and get that structured a little better? Maybe one call interferes with the other?</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/fade-one-color-to-another-color-wemos-nodemcu/#post-4809</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4808</link>
                        <pubDate>Fri, 24 Mar 2023 12:20:36 +0000</pubDate>
                        <description><![CDATA[I agree with you regarding the function naming.I fully understand your lack of time, since I am sure many need your help.
I think the flickering may be caused by the part
if (updateFadeCol...]]></description>
                        <content:encoded><![CDATA[<p>I agree with you regarding the function naming.<br />I fully understand your lack of time, since I am sure many need your help.</p>
<p>I think the flickering may be caused by the part</p>
<pre contenteditable="false">if (updateFadeColors2 == true) {
    fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
  }</pre>
<p>Even when finished fading the fadeTo2 continues to start.</p>
<p>I am not sure where to set the updateFadeColors2 to false in order to stop the fadeTo2</p>
<p>Maybe if possible, I could send you the whole Wemos project (about 20 Kb)</p>
<p><br />By the way I am also using WiFi and OTA in my project</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/fade-one-color-to-another-color-wemos-nodemcu/#post-4808</guid>
                    </item>
				                    <item>
                        <title>RE: Fade one color to another color Wemos / NodeMCU</title>
                        <link>https://www.tweaking4all.com/forum/arduino/fade-one-color-to-another-color-wemos-nodemcu/#post-4807</link>
                        <pubDate>Fri, 24 Mar 2023 09:53:41 +0000</pubDate>
                        <description><![CDATA[I presume it flickers when calling fadeTo2? (sorry - took me quite a bit of reading to figure out what you meant and what the code may be doing)
Not sure why it would flicker, but I can ima...]]></description>
                        <content:encoded><![CDATA[<p>I presume it flickers when calling fadeTo2? (sorry - took me quite a bit of reading to figure out what you meant and what the code may be doing)</p>
<p>Not sure why it would flicker, but I can image there is room for improvement to speed up things.</p>
<p>A few ideas ...</p>
<p>To reduce confusion when reading code maybe it is better we change the name of this functions.<br />The original fade-to-color developer used the same names as the other function, which is not incorrect, but I found this to be confusing at times when reading code.</p>
<p>So let's change this function</p>
<pre contenteditable="false">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;
}</pre>
<p>to maybe this (or whatever name you prefer):</p>
<pre contenteditable="false">CRGB fadeOneColor( 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;
}</pre>
<p>You will have to update these two functions (fadeTowardColor and fadeTowardColor2) to this, so it uses the new name:</p>
<pre contenteditable="false">// Fade an entire array of CRGBs toward a given background color by a given amount
// This function modifies the pixel array in place.
void fadeTowardColor( CRGB* L, uint16_t N, const CRGB&amp; bgColor, uint8_t fadeAmount)
{
  for( uint16_t i = 0; i &lt; N; i++) {
    fadeOneColor( L, bgColor, fadeAmount);
  }
}

void fadeTowardColor2( CRGB* L, uint16_t N, const CRGB&amp; bgColor, const CRGB&amp; bgColor2, uint8_t fadeAmount)
{
  for( uint16_t i = 0; i &lt; N; i++) {
    if ((i % 2) == 0) {
      fadeOneColor( L, bgColor, fadeAmount);
    } else {
      fadeOneColor( L, bgColor2, fadeAmount);
    }
  }
}</pre>
<p> </p>
<p> </p>
<p>Next, the entire strip is either one or two colors, so instead of recalculating the new color for each individual LED, we could calculate the new color only one time and copy it to the other LEDs. This would potentially be significantly faster.</p>
<p>Maybe something like this (calculate once, and copy it for all LEDs);</p>
<pre contenteditable="false">// Fade an entire array of CRGBs toward a given background color by a given amount
// This function modifies the pixel array in place.
void fadeTowardColor( CRGB* L, uint16_t N, const CRGB&amp; bgColor, uint8_t fadeAmount)
{
  fadeOneColor( L, bgColor, fadeAmount); // first LED - calc new color

  for( uint16_t i = 0; i &lt; N; i++) {
     L = L; // copy color from first LED
  }
}

void fadeTowardColor2( CRGB* L, uint16_t N, const CRGB&amp; bgColor, const CRGB&amp; bgColor2, uint8_t fadeAmount)
{
  fadeOneColor( L, bgColor, fadeAmount); // Calc new color first LED
  fadeOneColor( L, bgColor, fadeAmount); // and second LED

  for( uint16_t i = 0; i &lt; N; i++) {
    if ((i % 2) == 0) {
      L = L;  // copy 1st LED color
    } else {
      L = L; // copy seconde LED color
    }
  }
}</pre>
<p> </p>
<p>Next, I'd strip your code (in a copy of course) to just the 2 color fade related code ... just to make sure we get that to work first.<br />So remove as much as you can, just to stick to the barebones 2 color fade.</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/fade-one-color-to-another-color-wemos-nodemcu/#post-4807</guid>
                    </item>
							        </channel>
        </rss>
		