Code: Select all
#include <Adafruit_NeoPixel.h>
#include <IRremote.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
int itsONled[] = {0, 0, 0, 0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
unsigned long currentTime;
unsigned long previousMillis1 = 0;
//unsigned long previousMillis2 = 0;
//unsigned long previousMillis3 = 0;
//unsigned long interval = 120;
//int onTime = 500;
#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 code14 0xFF7A85// code received from button no. 3
#define code17 0xFF5AA5 // code received from button no. 6
#define code20 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);
pinMode(engineLED, OUTPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX); // Print Code in HEX
unsigned int value = results.value;
switch (value) {
case code14:
if (itsONled[1] == 1) { // if first led is on then
strip.show(); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
strip.begin();// turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
strip.Color(0, 255, 255, 0); // pixel color set to light blue
strip.show();
currentTime = millis();
// Begin Engine 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(25); // speed of color change
strip.setBrightness(0 + i); // brings up brightness from 0 to full
strip.show();
delay (25); // speed of brightening
} while (i < 255, c > 0);
// 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;
} break;
case code17:
if (itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code20:
if (itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
}
irrecv.resume(); // Receive the next value
}
}