run and repeat code until button is pressed with IR remote

so i been struggling with this for a while now. What i’m trying to do is after the code runs rainbowCycle it repeats it until something else button is pressed. so when i press button rainbowcycle starts and after for a while (5 spins) it stops and while its doing those 5 spins i cant change the color.

#include "Adafruit_NeoPixel.h"
#include "IRLibAll.h"

#define PIN 6
#define NUM_LEDS 60

IRrecv myReceiver(3);//receiver on pin 3
IRdecode myDecoder;//Decoder object

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
 strip.begin();
 strip.setBrightness(100);
 strip.show(); // Initialize all pixels to 'off'
 myReceiver.enableIRIn(); // Start the receiver
}

void loop() {
 if (myReceiver.getResults()) {
   myDecoder.decode();
   if (myDecoder.protocolNum == NEC) {
     switch (myDecoder.value) {
       case 0xFF6897: //n 0      AND n means the button from my ir remote
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 0, 0, 0); //all black/off
         break;
       case 0xFF30CF: //  n 1
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 120, 0, 0); //RED
         break;
       case 0xFF18E7:   //n2
         rainbowCycle(20);
         break;
       case 0xFF7A85: // n 3 GREEN
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 0, 120, 0); 
         break;
       case 0xFF38C7: // n 5
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 0, 150, 150); 
         break;
       case 0xFF10EF: // n 4
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 0, 0, 120); 
         break;

       case 0xFF5AA5: // n 6
         for (uint16_t i = 0; i < NUM_LEDS; i++)
           strip.setPixelColor(i, 150, 0, 100); //PURPLE
         break;
     }
     strip.show();
     myReceiver.enableIRIn(); //Restart the receiver
   }
 }

}

void rainbowCycle(int SpeedDelay) {
 byte *c;
 uint16_t i, j;

 for (j = 0; j < 256 *5; j++) { // The 5 here means it runs all color on wheel 5 times
   for (i = 0; i < NUM_LEDS; i++) { //problem is to get this run until something else of those buttons is pressed
     c = Wheel(((i * 256 / NUM_LEDS) + j) & 255);
     strip.setPixelColor(i, *c, *(c + 1), *(c + 2));
   }
   strip.show();
   delay(SpeedDelay);
 }
}

byte * Wheel(byte WheelPos) {
 static byte c[3];


 if (WheelPos < 85)
 {
   c[0] = WheelPos * 3;
   c[1] = 255 - WheelPos * 3;
   c[2] = 0;
 } else if (WheelPos < 170) {
   WheelPos -= 85;
   c[0] = 255 - WheelPos * 3;
   c[1] = 0;
   c[2] = WheelPos * 3;
 } else {
   WheelPos -= 170;
   c[0] = 0;
   c[1] = WheelPos * 3;
   c[2] = 255 - WheelPos * 3;
 }

 return c;
}

now the code is how it should be?

for (j = 0; j < 256 *5 1; j++) { // The 5 here means it runs all color on wheel 5 timesNot the answer to your question but what is that 1 doing in there ?

sorry i must have accidentally placed that there while i was doing those comments. so forget that 1 from there :grinning:

Please post code that actually compiles, and post it inside code tags please. It was already explained to you here, please don't ignore it.

OP tried :wink: see the square brackets in front and after the code

OP

Replace [ in the beginning by [code]
Replace ] at the end by [/code]

nobody knows the answer? is it even possible to make such a thing as repeting until something happens?

Please present the code correctly in code tags as has been requested multiple times, then we can talk.

The more you conform to forum standards, the more likely it is that someone will be interested in helping you. You’ve been requested to post your code (that actually compiles) with proper code tags. Why not start with that?

Regarding the code: You need to rewrite the Adafruit code to be non-blocking and not use delay(). To do this, you need to study up on the millis() timer technique. Here are some resources:

Arduino IDE: File --> Examples --> 02.Digital --> BlinkWithoutDelay