Detect and handle new IR signal

Hello Guys. I want to make a RGB Controller like these cheap ones from ebay witch comes witch each rgb Strip. Until now I have the following code and it works just fine. But how can I check if there is a new signal while the flash() Method? I've tried many different possibilities, but it doesn't work :( How would you check if the user presses a new key on the Remote control while the flash() and fadeBetweenColors() Method? The Code: https://hastebin.com/eqomakituj.cpp

PS: by the way: I use this IRLib2 https://github.com/cyborg5/IRLib2 because I have some problems with more common ir-reciever library

Thanks in advance

Given your flash() function is full of delays, your code is not architected in the right way. (and why 4 times delay(flashSpeed / 4) rather than one delay(flashSpeed) ???)

void flash() {
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    if(!checkIfNewSignal()){
      flash();
    }
}

either you hack into the function some IR reading or your re-architect the whole thing to do proper time management.

J-M-L: Given your flash() function is full of delays, your code is not architected in the right way. (and why 4 times delay(flashSpeed / 4) rather than one delay(flashSpeed) ???)

void flash() {
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    delay(flashSpeed / 4);
    setColourRgb((int)random((int)random(256)), (int) random((int)random(256)), (int) random((int)random(256)));
    if(!checkIfNewSignal()){
      flash();
    }
}

either you hack into the function some IR reading or your re-architect the whole thing to do proper time management.

I wanted to check if there is a new signal after each delay. An I divided the delay by 4 if the delay is to long. So how can i fix this ,,not architected code"?

I wanted to check if there is a new signal after each delay.

well it's nowhere in that code...

that could look something like this:

boolean actionDone= true; 

void loop()
{
   if IR command received then {actionDone = false; aCommand(true);}
   if (!actionDone) aCommand(false);
}

// an IR Command function should look like this

void aCommand(boolean firstLaunch)
{
   static unsigned long myStartTime;
   static unsigned long nextActionDelay;

   if (firstLaunch) {
     myStartTime = millis();
     nextActionDelay = 0;
   }

   if (millis() - myStartTime >= nextActionDelay) {
       // do here your next action


      if (action is terminated) actionDone = true; // TO BE DEFINED
      nextActionDelay = flashSpeed;// DEFINE TO HOW LONG YOU WANT TO WAIT FOR THE NEXT ANIMATION
   }
}

this way you do your animation step by step

(totally untested code, missing parts, it's conceptual)

Maybe it would work to sprinkle " if (ir.getResults()) return;" lines throughout your flash() function. That would end the flash function if an IR message is received.

DO NOT CALL flash() from inside flash() unless you know the recursion will terminate fairly quickly.

    if(!checkIfNewSignal()){
      flash();

Every time a function calls itself it uses some call-stack space in SRAM. On an Arduino it dos not take long for all of SRAM to fill up and cause a program crash. Just put an infinite loop (while(true){}) around the flashing part so it runs repeatedly forever. The statements to check for input will get you out of the loop so you can process input.

Thank you all so much. I will try this.