Having trouble exiting while loop with remote control

I’m quite new to this so i’m sure the answer is very simple. I’m writing a code to make my own LED strip with a receiver, controller and a RGBLED. I can easily toggle between each of the seperate colors that just glow until turned off. However, I have a while loop that runs some for loops that makes the LEDS slowly scroll through all the colors by mixing the brightness of each color. The scrolling works great and when I first turn the Arduino on, I can select some colors, but the second I hit the button for the scrolling colors, I can stop the loop and it just forever scrolls through the changing colors. I can turn the lights off with the switch or change the color. The only way to get it back to normal is to reload the code. What is wrong with my WHILE loop?

#include <IRremote.h>
int IRpin=6;
IRrecv IR(IRpin);
decode_results cmd;
String myCom;
int red=11;
int green=10;
int blue=9;
int i;
int r;
int j;
int k;
int f;
int a;
int dt=100;
int change=5;

void setup() {
  // put your setup code here, to run once:
Serial.begin(74800);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
IR.enableIRIn();
}

void loop() {
  // put your main code here, to run repeatedly:
while (IR.decode(&cmd)==0){               //waits until first controller button is pressed after arduino starts
  
}
Serial.println(cmd.value,HEX);
IR.resume();


if (cmd.value==0xFFA25D){                //Off
  digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF30CF){               //red
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF18E7){               //green
  digitalWrite(green,HIGH);
  digitalWrite(red,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF7A85){       //blue
  digitalWrite(green,LOW);
  digitalWrite(red,LOW);
  digitalWrite(blue,HIGH);
  }


while (cmd.value==0xFF10EF){        //PROBLEM LOOP(this needs the fixing)
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
  digitalWrite(red,HIGH);
for (i=0;i<=250;i=i+change){        //red on and green ramping up
  analogWrite(green,i);
  delay(dt);
}

digitalWrite(green,HIGH);         //green on and red ramping down
for (r=250;r>=0;r=r-change){
  analogWrite(red,r);
  delay(dt);
}

digitalWrite(green,HIGH);
for (j=0;j<=250;j=j+change){      //green on and blue ramping up
  analogWrite(blue,j);
  delay(dt);
}

digitalWrite(blue,HIGH);
for (k=250;k>=0;k=k-change){      //Blue on green ramping down
  analogWrite(green,k);
  delay(dt);
}
//blue on red ramping up
digitalWrite(blue,HIGH);          //blue on red ramping up
for (f=0;f<=250;f=f+change){
  analogWrite(red,f);
  delay(dt);
}

digitalWrite(red,HIGH);         //red on blue ramping down
for (a=250;a>=0;a=a-change){
  analogWrite(blue,a);
  delay(dt);
}
digitalWrite(red,HIGH);         //without this the red only flashes quickly
delay(1000);
}                               //end of while loop

}                               //end of void loop

troubleshooting.txt (2.26 KB)

Please post your code inline in your post, and place it between code tags using the </> button when you post.

#include <IRremote.h>
int IRpin=6;
IRrecv IR(IRpin);
decode_results cmd;
String myCom;
int red=11;
int green=10;
int blue=9;
int i;
int r;
int j;
int k;
int f;
int a;
int dt=100;
int change=5;

void setup() {
  // put your setup code here, to run once:
Serial.begin(74800);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
IR.enableIRIn();
}

void loop() {
  // put your main code here, to run repeatedly:
while (IR.decode(&cmd)==0){               //waits until first controller button is pressed after arduino starts
  
}
Serial.println(cmd.value,HEX);
IR.resume();


if (cmd.value==0xFFA25D){                //Off
  digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF30CF){               //red
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF18E7){               //green
  digitalWrite(green,HIGH);
  digitalWrite(red,LOW);
  digitalWrite(blue,LOW);
}

if (cmd.value==0xFF7A85){       //blue
  digitalWrite(green,LOW);
  digitalWrite(red,LOW);
  digitalWrite(blue,HIGH);
  }


while (cmd.value==0xFF10EF){        //PROBLEM LOOP(this needs the fixing)
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
  digitalWrite(red,HIGH);
for (i=0;i<=250;i=i+change){        //red on and green ramping up
  analogWrite(green,i);
  delay(dt);
}

digitalWrite(green,HIGH);         //green on and red ramping down
for (r=250;r>=0;r=r-change){
  analogWrite(red,r);
  delay(dt);
}

digitalWrite(green,HIGH);
for (j=0;j<=250;j=j+change){      //green on and blue ramping up
  analogWrite(blue,j);
  delay(dt);
}

digitalWrite(blue,HIGH);
for (k=250;k>=0;k=k-change){      //Blue on green ramping down
  analogWrite(green,k);
  delay(dt);
}
//blue on red ramping up
digitalWrite(blue,HIGH);          //blue on red ramping up
for (f=0;f<=250;f=f+change){
  analogWrite(red,f);
  delay(dt);
}

digitalWrite(red,HIGH);         //red on blue ramping down
for (a=250;a>=0;a=a-change){
  analogWrite(blue,a);
  delay(dt);
}
digitalWrite(red,HIGH);         //without this the red only flashes quickly
delay(1000);
}                               //end of while loop

}                               //end of void loop

Do not use delay. Do not use a while loop. Do not use a for loop.

Instead create separate global variables for red, green and blue. When you receive one copy of the ramping up/down code from the remote do one single step of the ramping up/down using the variable and perform the appropriate analogWrite() using the variable.

Edit: Pseudo code…

IF red ramping up remote code received...
  IF redRamp + change <= 255...
    redRamp += change
    analogWrite(redPin, redRamp)
  ENDIF
ENDIF

Thank you so much!