Been trying to solve the problem of running an LED strobe pattern while also running a NeoPixel LED ring pattern for an rc airplane lighting setup. Iv read a ton and tried unsuccessfully to replace the delay with if else loops. Any and all help would be greatly appreciated.
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 3
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB greenLeds[NUM_LEDS_PER_STRIP];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 4, NEO_RGB + NEO_KHZ800);
void setup() {
FastLED.addLeds<NEOPIXEL, 2>(redLeds, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 3>(greenLeds, NUM_LEDS_PER_STRIP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
//trying to get this to run at the same time
//{rainbowCycle(10);
//trying to replace this section with if else loop or something better
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
// set our current dot to red, green, and blue
redLeds[0] = CRGB::White;
redLeds[1] = CRGB::Red;
redLeds[2] = CRGB::Red;
greenLeds[0] = CRGB::White;
greenLeds[1] = CRGB::Green;
greenLeds[2] = CRGB::Green;
FastLED.show();
delay(100);
// clear our current dot before we move on
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
FastLED.show();
delay(50);
redLeds[0] = CRGB::White;
greenLeds[0] = CRGB::White;
FastLED.show();
delay(50);
// clear our current dot before we move on
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
FastLED.show();
delay(1000);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*1000000; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
Thanks