Good day! I have a trouble in my program. Basically, what I wanted it to happen was when I type in a certain word in the Serial Monitor, the RGB strip light would light up that certain color or command. So I used a series of if statements. My problem is that I also wanted to put in color swirl but when I use an if statement in only goes through the cycle once. So, I changed it and put it in a while statement. So now, my real problem is that when I put in the color swirl it doesn't stop even if I type in another command in the serial monitor. I have researched and said that I should use break? to stop the loop? But I don't know where in my program should I put it. I attached my whole program below. But this is where I got a problem. Thanks in advance!
while (command.equals("color swirl")){
//blue to violet
for (r=0;r<256;r++){
analogWrite(red, r);
delay(fade);
}
//violet to red
for (b=255;b>0;b--){
analogWrite(blue, b);
delay(fade);
}
//red to yellow
for (g=0;g<255;g++){
analogWrite(green, g);
delay(fade);
}
//yellow to green
for (r=255;r>0;r--){
analogWrite(red, r);
delay(fade);
}
//green to teal
for (b=0;b<255;b++){
analogWrite(blue, b);
delay(fade);
}
//teal to blue
for (g=255;g>0;g--){
analogWrite(green, g);
delay(fade);
}
if (!command.equals("color swirl")){
!command.equals("color swirl");
break;
}
}
RGB_whole_program_serial.ino (2.3 KB)