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?