I'm using Adafruit to program one addressable LED strip that's 12 lights long, and four "circles" of LEDs which is one light surrounded by six lights, and they're all addressable. On the strip, I'm trying to get blue lights to climb up, stay lit for a bit, then all turn off for a bit. On the circles, I'm trying to get one circle to light up all in red, then turn off and another circle lights up all in red, and so on in a cycle. (It's a Ghostbusters proton pack, the strip is the power bar and the four circles are the lights on the cyclotron.)
Using delay, I was able to get one code to get the power bar to work, and a separate code to get the cyclotron to work. But after struggling with millis() forever to try to combine the two, I gave up. I thought I'd try to fake running both at the same time using delay.
So what I'm trying to do is have the first circle of light to turn on, then turn on the first five lights on the power bar turn on in sequence. Then the first circle of light turns off, and the second circle of lights turns on, and then lights 6 through 10 on the power bar turns on in sequence. Then the third circle turns on, lights 11 then 12 turns on and remains on. The fourth circle turns on, and after a wait, the power bar turns off, and after a wait, the loop should start again.
When I try to run the code, the power bar runs correctly for three cycles and then remains on. The first circle of lights will turn on, but the rest won't. Anyone know what the issue is?
#include <Adafruit_NeoPixel.h>
// Pin of LED strip
uint8_t stripPin = 5;
//Pin for each circle of LEDS
uint8_t circlePin[] = {10,11,12,13};
// Number of lights in LED strip
#define numberOfPixels 12
//Size of each LED circle
#define circleNumberOfPixels 7
//Color of LED circles based on RGB values
uint8_t circleLightColor[] = {255, 0, 0};
//Color of lights based on RGB values
uint8_t stripLightColor[] = {0, 0, 255};
//Brightness of LED Circles
#define circleBrightness 127
//Brightness of LED strip
#define stripBrightness 127
//Create an LED object for each pin
Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(numberOfPixels, stripPin);
Adafruit_NeoPixel ledCircle0 = Adafruit_NeoPixel(circleNumberOfPixels,circlePin[0]);
Adafruit_NeoPixel ledCircle1 = Adafruit_NeoPixel(circleNumberOfPixels,circlePin[1]);
Adafruit_NeoPixel ledCircle2 = Adafruit_NeoPixel(circleNumberOfPixels,circlePin[2]);
Adafruit_NeoPixel ledCircle3 = Adafruit_NeoPixel(circleNumberOfPixels,circlePin[3]);
Adafruit_NeoPixel circleArray[] = {ledCircle0,ledCircle1,ledCircle2,ledCircle3};
enum CircCycle {CIRCLE1,CIRCLE2,CIRCLE3,CIRCLE4};
CircCycle currentCycle = CIRCLE1;
void setup() {
ledStrip.begin();
ledStrip.setBrightness(stripBrightness);
ledStrip.clear();
ledStrip.show();
for (uint8_t n=0;n<=sizeof(circlePin);n++){
circleArray[n].begin();
circleArray[n].clear();
circleArray[n].show();
circleArray[n].setBrightness(circleBrightness);
}
}
void loop() {
switch (currentCycle) {
case CIRCLE1:
ledCircle3.clear();
ledCircle3.show();
circleLightsOn (ledCircle0, circleLightColor[0], circleLightColor[1], circleLightColor[2]);
stripLightRegular (0,100);
stripLightRegular (1,100);
stripLightRegular (2,100);
stripLightRegular (3,100);
stripLightRegular (4,63);
currentCycle=CIRCLE2;
break;
case CIRCLE2:
ledCircle0.clear();
ledCircle0.show();
circleLightsOn (ledCircle1, circleLightColor[0], circleLightColor[1], circleLightColor[2]);
delay(37);
stripLightRegular (5,100);
stripLightRegular (6,100);
stripLightRegular (7,100);
stripLightRegular (8,100);
stripLightRegular (9,26);
currentCycle=CIRCLE3;
break;
case CIRCLE3:
ledCircle1.clear();
ledCircle1.show();
circleLightsOn (ledCircle2, circleLightColor[0], circleLightColor[1], circleLightColor[2]);
delay(74);
stripLightRegular (10,100);
stripLightRegular (11, 289);
currentCycle=CIRCLE4;
break;
case CIRCLE4:
ledCircle2.clear();
ledCircle2.show();
circleLightsOn (ledCircle2, circleLightColor[0], circleLightColor[1], circleLightColor[2]);
delay(113);
ledStrip.clear();
ledStrip.show();
delay(350);
currentCycle=CIRCLE1;
break;
}
}
void stripLightRegular (uint8_t offset, uint16_t delayVal) {
ledStrip.setPixelColor(offset, ledStrip.Color(stripLightColor[0], stripLightColor[1], stripLightColor[2]));
ledStrip.show();
delay(delayVal);
}
void circleLightsOn (Adafruit_NeoPixel circle, uint8_t red,uint8_t green,uint8_t blue){
for (uint8_t k=0; k<=circleNumberOfPixels;k++) {
circle.setPixelColor(k,red, green, blue);
}
circle.show();
}