user6666: I'm working on a function to fade RGB LEDs smoothly from one color to the next, so I thought I'd use a for loop  to increment each RGB value according with the set value. I've made the for loop as following:
for (redFadeCurrent, greenFadeCurrent, blueFadeCurrent;
   ((redFadeCurrent != redFadeTarget)&&
   (greenFadeCurrent != greenFadeTarget)&&
   (blueFadeCurrent != blueFadeTarget));
   redFadeCurrent = redFadeCurrent + redStep,
   greenFadeCurrent = greenFadeCurrent + greenStep, 
   blueFadeCurrent = blueFadeCurrent + blueStep) {

    analogWrite(ledRedPin, redFadeCurrent);
    analogWrite(ledGreenPin, greenFadeCurrent);
    analogWrite(ledBluePin, blueFadeCurrent);
    Serial.print("Red: "); 
    Serial.print(redFadeCurrent);
    Serial.print(" Green: "); 
    Serial.print(greenFadeCurrent);
    Serial.print(" Blue: "); 
    Serial.println(blueFadeCurrent);
    delay(3000);

    if (redFadeCurrent>redFadeTarget) {
        redStep = -1;
    }
    else if (redFadeCurrent<redFadeTarget) {
        redStep = +1;
    }
    else {
        redStep = 0;
    }

    if (greenFadeCurrent>greenFadeTarget) {
        greenStep = -1;
    }
    else if (greenFadeCurrent<greenFadeTarget) {
        greenStep = +1;
    }
    else {
        greenStep = 0;
    }

    if (blueFadeCurrent>blueFadeTarget) {
        blueStep = -1;
    }
    else if (blueFadeCurrent<blueFadeTarget) {
        blueStep = +1;
    }
    else {
        blueStep = 0;
    }

Problem is, when one of the values hit the target the code leaves the for loop. 
I'm guessing the condition ((redFadeCurrent != redFadeTarget)&&(greenFadeCurrent != greenFadeTarget)&&(blueFadeCurrent != blueFadeTarget)) does not work. 
Is there any way to work around this? 
Thanks is advance.

user630: You are correct, the problem is the condition inside the for statement.
Let's examine what happens when the red LED hits its fading target, which is, say, 100 (for the sake of the example, I will fabricate the other values):
for (...; (100 != 100) && (90 != 100) && (80 != 100) ; ... )


(100 != 100) -> FALSE 
(90 != 100) -> TRUE
(80 != 100) -> TRUE

FALSE && TRUE && TRUE -> FALSE
The condition inside the for evaluates to FALSE, therefor the loop will exit. 
If you want the loop to continue as long as there is at least one LED which hasn't hit the fading target, you should change the AND to OR:
((redFadeCurrent != redFadeTarget) || (greenFadeCurrent != greenFadeTarget) ||
   (blueFadeCurrent != blueFadeTarget))

Let's examine what happens now with the same values:
for (...; (100!=100) || (90 != 100) || (80 != 100) ; ...)


(100 != 100) -> FALSE
(90 != 100) -> TRUE
(80 != 100) -> TRUE

FALSE || TRUE || TRUE -> TRUE ==> The loop will continue. 
And what will happen when all the colors hit the fading targets?
for (...; (100!=100) || (100 != 100) || (100 != 100) ; ...)


(100 != 100) -> FALSE 
(100 != 100) -> FALSE 
(100 != 100) -> FALSE 

FALSE || FALSE || FALSE -> FALSE ==> The loop will stop since the condition will not evaluate to TRUE.

6666: <p>I'm working on a function to fade RGB LEDs smoothly from one color to the next, so I thought I'd use a for loop  to increment each RGB value according with the set value. I've made the for loop as following:</p>

<pre><code>for (redFadeCurrent, greenFadeCurrent, blueFadeCurrent;
   ((redFadeCurrent != redFadeTarget)&amp;&amp;
   (greenFadeCurrent != greenFadeTarget)&amp;&amp;
   (blueFadeCurrent != blueFadeTarget));
   redFadeCurrent = redFadeCurrent + redStep,
   greenFadeCurrent = greenFadeCurrent + greenStep, 
   blueFadeCurrent = blueFadeCurrent + blueStep) {

    analogWrite(ledRedPin, redFadeCurrent);
    analogWrite(ledGreenPin, greenFadeCurrent);
    analogWrite(ledBluePin, blueFadeCurrent);
    Serial.print("Red: "); 
    Serial.print(redFadeCurrent);
    Serial.print(" Green: "); 
    Serial.print(greenFadeCurrent);
    Serial.print(" Blue: "); 
    Serial.println(blueFadeCurrent);
    delay(3000);

    if (redFadeCurrent&gt;redFadeTarget) {
        redStep = -1;
    }
    else if (redFadeCurrent&lt;redFadeTarget) {
        redStep = +1;
    }
    else {
        redStep = 0;
    }

    if (greenFadeCurrent&gt;greenFadeTarget) {
        greenStep = -1;
    }
    else if (greenFadeCurrent&lt;greenFadeTarget) {
        greenStep = +1;
    }
    else {
        greenStep = 0;
    }

    if (blueFadeCurrent&gt;blueFadeTarget) {
        blueStep = -1;
    }
    else if (blueFadeCurrent&lt;blueFadeTarget) {
        blueStep = +1;
    }
    else {
        blueStep = 0;
    }
</code></pre>

<p>Problem is, when one of the values hit the target the code leaves the for loop. 
I'm guessing the condition <code>((redFadeCurrent != redFadeTarget)&amp;&amp;(greenFadeCurrent != greenFadeTarget)&amp;&amp;(blueFadeCurrent != blueFadeTarget))</code> does not work. </p>

<p>Is there any way to work around this? </p>

<p>Thanks is advance.</p>
 630: <p>You are correct, the problem is the condition inside the <code>for</code> statement.</p>

<p>Let's examine what happens when the <em>red</em> LED hits its fading target, which is, say, 100 (for the sake of the example, I will fabricate the other values):</p>

<pre><code>for (...; (100 != 100) &amp;&amp; (90 != 100) &amp;&amp; (80 != 100) ; ... )
</code></pre>

<ul>
<li>(100 != 100) -> <strong>FALSE</strong> </li>
<li>(90 != 100) -> <strong>TRUE</strong></li>
<li>(80 != 100) -> <strong>TRUE</strong></li>
</ul>

<p><strong>FALSE</strong> &amp;&amp; <strong>TRUE</strong> &amp;&amp; <strong>TRUE</strong> -> <strong>FALSE</strong></p>

<p>The condition inside the <code>for</code> evaluates to <code>FALSE</code>, therefor the loop will exit. </p>

<p>If you want the loop to continue as long as there is at least one LED which hasn't hit the fading target, you should change the <code>AND</code> to <code>OR</code>:</p>

<pre><code>((redFadeCurrent != redFadeTarget) || (greenFadeCurrent != greenFadeTarget) ||
   (blueFadeCurrent != blueFadeTarget))
</code></pre>

<p>Let's examine what happens now with the same values:</p>

<pre><code>for (...; (100!=100) || (90 != 100) || (80 != 100) ; ...)
</code></pre>

<ul>
<li>(100 != 100) -> FALSE</li>
<li>(90 != 100) -> TRUE</li>
<li>(80 != 100) -> TRUE</li>
</ul>

<p><strong>FALSE</strong> || <strong>TRUE</strong> || <strong>TRUE</strong> -> <strong>TRUE</strong> ==> The loop will continue. </p>

<p>And what will happen when all the colors hit the fading targets?</p>

<pre><code>for (...; (100!=100) || (100 != 100) || (100 != 100) ; ...)
</code></pre>

<ul>
<li>(100 != 100) -> FALSE </li>
<li>(100 != 100) -> FALSE </li>
<li>(100 != 100) -> FALSE </li>
</ul>

<p><strong>FALSE</strong> || <strong>FALSE</strong> || <strong>FALSE</strong> -> <strong>FALSE</strong> ==> The loop will stop since the condition will not evaluate to <code>TRUE</code>.</p>
