#include <Adafruit_NeoPixel.h>
#define PIN_WS2812 2 // WS2812B data pin
#define NUM_PIXELS 16 // Number of pixels in the strip
#define PIN_RIGHT 3 // Pin for right indicator
#define PIN_LEFT 4 // Pin for left indicator
#define PIN_WHITE 6 // Pin for dynamic white effect
#define PIN_RAINBOW 5 // Pin for rainbow effect with white sparkle
#define PIN_RED 7 // Pin for red light with low brightness
#define PIN_SPARKLE 11 // Pin for Hyper Sparkle effect
#define PIN_AIRPLANE 8 // Pin for airplane light effect
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN_WS2812, NEO_GRB + NEO_KHZ800);
// Function to turn off all pixels
void clearStrip() {
for (int i = 0; i < NUM_PIXELS; i++) {
strip.setPixelColor(i, 0);
}
strip.show();
}
// Hazard light flow running effect with LEDs off at the end and 1ms delay
void hazardFlowEffect(uint32_t color, int delayTime) {
for (int i = 0; i < NUM_PIXELS / 2; i++) {
strip.setPixelColor((NUM_PIXELS / 2) - i - 1, color); // Left side
strip.setPixelColor((NUM_PIXELS / 2) + i, color); // Right side
strip.show();
delay(100);
}
clearStrip(); // Turn off LEDs at the end of the effect
delay(300); // 1 ms delay before repeating
}
// Welcome effect: 3-time orange flow from the middle
void welcomeEffect() {
for (int i = 0; i < 3; i++) {
hazardFlowEffect(strip.Color(255, 165, 0), 50); // Orange color
delay(250);
}
}
// Right indicator flow effect
void rightFlowEffect(uint32_t color, int delayTime) {
for (int i = 0; i < NUM_PIXELS / 2; i++) {
strip.setPixelColor((NUM_PIXELS / 2) + i, color); // Right side
strip.show();
delay(100);
}
clearStrip();
delay(300); // 1 ms delay before repeating
}
// Left indicator flow effect
void leftFlowEffect(uint32_t color, int delayTime) {
for (int i = 0; i < NUM_PIXELS / 2; i++) {
strip.setPixelColor((NUM_PIXELS / 2) - i - 1, color); // Left side
strip.show();
delay(100);
}
clearStrip();
delay(300); // 1 ms delay before repeating
}
// Red light with low brightness
void redLightLowBrightness() {
uint32_t redColor = strip.Color(50, 0, 0); // Low brightness red
for (int i = 0; i < NUM_PIXELS; i++) {
strip.setPixelColor(i, redColor);
}
strip.show();
}
// Rainbow effect towards the center with white sparkle
void rainbowToCenterWithSparkle() {
for (long firstPixelHue = 0; firstPixelHue < 65536; firstPixelHue += 256) {
for (int i = 0; i < NUM_PIXELS / 2; i++) {
int hue = firstPixelHue + (i * 65536L / (NUM_PIXELS / 2));
uint32_t rainbowColor = strip.gamma32(strip.ColorHSV(hue, 255, 100));
strip.setPixelColor((NUM_PIXELS / 2) - i - 1, rainbowColor); // Left side
strip.setPixelColor((NUM_PIXELS / 2) + i, rainbowColor); // Right side
}
if (random(10) < 3) {
int sparklePixel = random(NUM_PIXELS);
strip.setPixelColor(sparklePixel, strip.Color(255, 255, 255)); // High brightness white
}
strip.show();
delay(20);
}
clearStrip();
delay(1); // 1 ms delay before repeating
}
// Hyper Sparkle effect
void hyperSparkleEffect() {
for (int i = 0; i < 20; i++) {
int pixel = random(NUM_PIXELS);
strip.setPixelColor(pixel, strip.Color(255, 255, 255)); // White sparkle
strip.show();
delay(50);
clearStrip();
delay(50);
}
}
// Airplane light effect
void airplaneLightEffect() {
while (digitalRead(PIN_AIRPLANE) == HIGH) { // Run while the pin is HIGH
strip.setPixelColor(0, strip.Color(255, 0, 0)); // Pixel 1: Red
strip.setPixelColor(7, strip.Color(255, 255, 255)); // Pixel 8: White
strip.setPixelColor(8, strip.Color(255, 255, 255)); // Pixel 9: White
strip.setPixelColor(15, strip.Color(0, 255, 0)); // Pixel 16: Green
strip.show();
delay(1); // 1 ms flashing
clearStrip();
delay(1); // 1 ms delay before flashing again
}
}
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(PIN_RIGHT, INPUT);
pinMode(PIN_LEFT, INPUT);
pinMode(PIN_WHITE, INPUT);
pinMode(PIN_RAINBOW, INPUT);
pinMode(PIN_RED, INPUT);
pinMode(PIN_SPARKLE, INPUT);
pinMode(PIN_AIRPLANE, INPUT); // Set airplane pin as input
welcomeEffect(); // Run welcome effect on power-up
}
void loop() {
bool rightSignal = digitalRead(PIN_RIGHT);
bool leftSignal = digitalRead(PIN_LEFT);
bool whiteSignal = digitalRead(PIN_WHITE);
bool rainbowSignal = digitalRead(PIN_RAINBOW);
bool redSignal = digitalRead(PIN_RED);
bool sparkleSignal = digitalRead(PIN_SPARKLE);
bool airplaneSignal = digitalRead(PIN_AIRPLANE);
if (rightSignal && leftSignal) {
// Both signals received, activate hazard mode
hazardFlowEffect(strip.Color(255, 165, 0), 50); // Hazard mode: Orange flow from center
} else if (rightSignal) {
// Only right signal received
rightFlowEffect(strip.Color(255, 165, 0), 50); // Right indicator
} else if (leftSignal) {
// Only left signal received
leftFlowEffect(strip.Color(255, 165, 0), 50); // Left indicator
} else if (whiteSignal) {
// Dynamic white flow effect
hazardFlowEffect(strip.Color(255, 255, 255), 50); // Hold if white signal received
} else if (rainbowSignal) {
// Rainbow effect with white sparkle
rainbowToCenterWithSparkle(); // Hold if rainbow signal received
} else if (redSignal) {
// Red light with low brightness
redLightLowBrightness(); // Hold if red signal received
} else if (sparkleSignal) {
// Hyper Sparkle effect
hyperSparkleEffect(); // Hold if sparkle signal received
} else if (airplaneSignal) {
// Airplane light effect
airplaneLightEffect(); // Hold if airplane signal received
} else {
clearStrip(); // Turn off all effects if no signals are received
}
}