Now in my best English translator; I have made a code where I can fade the neopixel (slowly from out to on or vice versa). I use an array to write back the value. But I do notice that the return statement does exactly what I don't want it to do.
The function: (the serial is debug for me)
void Fade(int W_R, int W_G, int W_B, int W1, int W2, int W3) {
Serial.print("W_R = "); Serial.print(W_R); Serial.print(" W1 = "); Serial.println(W1);
Serial.print("W_G = "); Serial.print(W_G); Serial.print(" W2 = "); Serial.println(W2);
Serial.print("W_B = "); Serial.print(W_B); Serial.print(" W3 = "); Serial.println(W3);
for (int x = 0; x <= 255;)
{
//ROOD
if (W_R > W1)
{
W_R -= 1;
Serial.println("WR>W1");
}
else if (W_R < W1)
{
W_R += 1;
Serial.println("WR<W1");
}
else if (W_R == W1)
{
Serial.println("WR==W1");
//return W_R;
}
//GROEN
if (W_G > W2)
{
W_G -= 1;
Serial.println("WG>W2");
}
else if (W_G < W2)
{
W_G += 1;
Serial.println("WG<W2");
}
else if (W_G == W2)
{
Serial.println("WG==W2");
//return W_G;
}
//BLAUW
if (W_B > W3)
{
W_B -= 1;
Serial.println("WB>W3");
}
else if (W_B < W3)
{
W_B += 1;
Serial.println("WB<W3");
}
else //if (W_B == W3)
{
Serial.println("WB==W3");
// return W_B;
}
NeoPixel(W_R, W_G, W_B, false, 0);
if(W_R == W1 && W_G == W2 && W_B == W3)
{
return W_R; return W_G; return W_B;
}
delay(10);
x += 1;
}
}
The intention is that he writes back the value of the color that the neopixel has. Now in this program, if he enters the "if", he skips the step (as it would with a normal "return"). Is it me or is this because arduino has had an update? (I use IDE arduino 1.8.10)
the function called:
Fade(rgb[0],rgb[1],rgb[2],255,0,0);
it does his work if it go from 0 to target, but otherwise it doesn't work