Hi arduinos,
I wrote a little piece of code that should increment values until they all reach their target value, but the function stops as soon as one value reaches its target. Shouldn't the WHILE loop stop only when all three values are equal to their respective targets because of the AND operators?
Thanks
int R = 0; //actual targets
int G = 0;
int B = 0;
int targetR = 10; //target values
int targetG = 20;
int targetB = 30;
void setup() {
Serial.begin(9600);
}
void loop() {
while (targetR != R && targetG != G && targetG != B){
smooth();
debugout();
}
}
void smooth(){
if (targetR > R){
R++;
}
if (targetG > G){
G++;
}
if (targetB > B){
B++;
}
}
void debugout(){
Serial.print(" R ");
Serial.print(R);
Serial.print(" G ");
Serial.print(G);
Serial.print(" B ");
Serial.print(B);
Serial.println();
}