A second set of eyes to review my code may be helpful. I have rearranged code, commented out and determined that the last section "// Begin Light Flicker " (line 123) is effecting the other LED's from turning on. I have this code working without the flicker part, and can comment it out and the other lights work. I am wondering if it has something to do with my use of millis and the random brightness settings of code that are not allowing the other LED's to turn on?
My setup is a Neopixel 12 LED ring that on setup ramps color up and then during the loop flickers randomly. The other three LED are IR controlled and should turn on with button presses from the IR and then I am using the millis command to turn them off after a certain period.
Should I break that last section out into another Switch / Case? Or something else?
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
int RECV_PIN = 2; // the pin where you connect the output pin of sensor
int led1 = 8; // headlights
int led2 = 9; // red warning lights
int led3 = 10; //interior solid
int led4 = 11; //interior blinking
unsigned long currentTime0;
unsigned long currentTime1;
unsigned long currentTime2;
unsigned long currentTime3;
int onTime0 = 35;
int onTime1 = 10000;
int onTime2 = 10000;
int onTime3 = 10000;
unsigned long previousMillis1 = 0;
#define PIN 6 // defines NEOPIXEL pin
#define engineLED 3 // engine warm-up sound fx activation pin
#define LED_COUNT 12 // defines NEOPIXEL light count
#define code1 0xFF7A85// code received from button no. 3
#define code2 0xFF5AA5 // code received from button no. 6
#define code3 0xFF52AD // code received from button no. 9
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
strip.begin();
strip.Color(0, 255, 255, 0); // pixel color set to light blue
strip.show();
currentTime0 = millis();
// Begin Engine LED Warmup
int i = 0;
int c = 255;
do {
i = i + 1;
c = c - 1;
strip.setPixelColor(0, 0, c, 255); // set pixel color
strip.setPixelColor(1, 0, c, 255); // set pixel color
strip.setPixelColor(2, 0, c, 255); // set pixel color
strip.setPixelColor(3, 0, c, 255); // set pixel color
strip.setPixelColor(4, 0, c, 255); // set pixel color
strip.setPixelColor(5, 0, c, 255); // set pixel color
strip.setPixelColor(6, 0, c, 255); // set pixel color
strip.setPixelColor(7, 0, c, 255); // set pixel color
strip.setPixelColor(8, 0, c, 255); // set pixel color
strip.setPixelColor(9, 0, c, 255); // set pixel color
strip.setPixelColor(10, 0, c, 255); // set pixel color
strip.setPixelColor(11, 0, c, 255); // set pixel color
strip.show();
delay(35); // speed of color change
strip.setBrightness(0 + i); // brings up brightness from 0 to full
strip.show();
delay (35); // speed of brightening
} while (i < 255, c > 0);
}
void loop()
{
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch (value) {
case code1:
digitalWrite(led1, HIGH); // turn it on when the button is pressed
currentTime1 = millis();
break;
}
irrecv.resume(); // Receive the next value
}
if ((millis() - currentTime1) >= onTime1)
{
digitalWrite(led1, LOW); // turn it off based on time
}
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch (value) {
case code2:
digitalWrite(led2, HIGH); // turn it on when the button is pressed
currentTime2 = millis();
break;
}
irrecv.resume(); // Receive the next value
}
if ((millis() - currentTime2) >= onTime2)
{
digitalWrite(led2, LOW); // turn it off based on time
}
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch (value) {
case code3:
digitalWrite(led3, HIGH); // turn it on when the button is pressed
currentTime3 = millis();
break;
}
irrecv.resume(); // Receive the next value
}
if ((millis() - currentTime3) >= onTime3)
{
digitalWrite(led3, LOW); // turn it off based on time
}
}
{
// Begin Light Flicker
strip.setBrightness(random(25, 255)); // random brightness adjust for flicker effect
strip.show();
unsigned long currentMillis1 = millis(); // random time adjust for brightness
if (currentMillis1 - previousMillis1 > (random(500, 1200))) {
previousMillis1 = currentMillis1;
}
}
}
}
}