Stop a while loop with ir remote

So I’m working on an RGB led driver. and I’m currently stuck on trying to stop the while loop with an IR remote. I want the RGB led to chose a random RGB number when the specific remote button is pressed. but when it starts flashing and randomizing the colors I can’t stop it cause of delay I think. and I can’t figure out how to do it.

case 0xFFE817: //Quick
if (results.value == 0xFFE817){
lastCode = results.value;

while (0xFFE817){
randRed = random(0, 255);
randGreen = random(0, 255);
randBlue = random(0, 255);
delay(200);
setColor(randRed, randGreen, randBlue);
}
if (results.value == 0xFF22DD){
break;
}
}
break;

patrik_laminar.ino (8.22 KB)

 while (0xFFE817){

How will that even be false?

My suggestion, don't use a while loop and don't use delay. Instead, let loop() do the looping (and use state change detection probably) and use millis() for all timing.

I know that cant is false but iwe been trying everything. but if I put it in the loop will that go all the time?

Yes, so only do it when you want it :slight_smile:

aight im gonna work on it and see what i can do

I've deleted your other cross post @LarsGunnar.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@pert alright i posted on this, cause i felt that it didnt fit in the other forum. @septillion but btw got it working now

I'm glad to hear you got it working. If you ever need to have a post moved to a different section of the forum, just click the "Report to moderator" button and request that it be moved.

the delay function is only for beginners doing very simple things. to do anything more with these boards you should NEVER use delay. these boards are single thread so using delay stops your board completely and you cant do any type of multitasking. my advice to anyone wanting to code anything serious is to forget the delay function exists.

instead get into the habit of setting up timers using millis() and it is amazing what you can eventually do with these little boards.

google "arduino blink without delay" for a very basic example of setting up a timer. you should adjust your coding approach to use timers for timeing instead of delay