#include <FastLED.h>
#define DATA_PIN 11
#define LED_COUNT 5
CRGB leds[LED_COUNT];
#define BUTTON_A0_PIN A0
#define BUTTON_A1_PIN A1
#define BUTTON_A2_PIN A2
#define BUTTON_2_PIN 2
#define BUTTON_3_PIN 3
#define BUTTON_4_PIN 4
#define BUTTON_5_PIN 5
#define BUTTON_6_PIN 6
#define BUTTON_7_PIN 7
int outputPin = A5; //trigger to mp3 player
#define COOLING 55
#define SPARKING 120
#define NUM_LEDS 5
#define gReverseDirection 0
uint8_t gHue = 0; // rotatin "base color" used by many of the patterns
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, LED_COUNT);
FastLED.setBrightness(120); // Adjust the brightness as needed
pinMode(BUTTON_A0_PIN, INPUT); // LDR input
pinMode(BUTTON_A1_PIN, INPUT_PULLUP); //north path reflective sensor
pinMode(BUTTON_A2_PIN, INPUT_PULLUP); // south path reflective sensor
pinMode(BUTTON_3_PIN, INPUT_PULLUP);
pinMode(BUTTON_4_PIN, INPUT_PULLUP);
pinMode(BUTTON_5_PIN, INPUT_PULLUP);
pinMode(BUTTON_6_PIN, INPUT_PULLUP);
pinMode(BUTTON_7_PIN, INPUT_PULLUP);
pinMode(outputPin, OUTPUT); // output to trigger mp3
uint8_t gHue = 0; // rotatin "base color" used by many of the patterns
}
void loop() {
// Check if button A1 is pressed
if (digitalRead(BUTTON_A1_PIN) == LOW && digitalRead(BUTTON_A0_PIN) == HIGH){
Path1();
}
// Check if button A2 is pressed
if (digitalRead(BUTTON_A2_PIN) == LOW && digitalRead(BUTTON_A0_PIN) == HIGH){
Path2();
}
// Check if button 2 is pressed
if (digitalRead(BUTTON_2_PIN) == LOW) {
turnOffLEDs();
}
// Check if button 3 is pressed
if (digitalRead(BUTTON_3_PIN) == LOW) {
RainbowPattern();
}
// Check if button 4 is pressed
if (digitalRead(BUTTON_4_PIN) == LOW) {
RainbowWithGlitterPattern();
}
// Check if button 5 is pressed
if (digitalRead(BUTTON_5_PIN) == LOW) {
ConfettiPattern();
}
// Check if button 6 is pressed
if (digitalRead(BUTTON_6_PIN) == LOW) {
SineLonPattern();
}
// Check if button 7 is pressed
if (digitalRead(BUTTON_7_PIN) == LOW) {
Fire2012Pattern();
}
}
void Path1() {
digitalWrite(outputPin, HIGH); // Turn ON output on pin A5
leds[0] = CRGB::Blue; //
FastLED.show();
delay(500);
leds[1] = CRGB::Blue; //
FastLED.show();
delay(500);
leds[2] = CRGB::Blue; //
FastLED.show();
delay(500);
leds[3] = CRGB::Blue; //
FastLED.show();
delay(500);
leds[4] = CRGB::Blue; //
FastLED.show();
delay(2000); // time lights wil stay on
digitalWrite(outputPin, LOW); // Turn off output on pin A5
}
void Path2() {
digitalWrite(outputPin, HIGH); // Turn ON output on pin A5
leds[4] = CRGB::White; //
FastLED.show();
delay(500);
leds[3] = CRGB::White; //
FastLED.show();
delay(500);
leds[2] = CRGB::White; //
FastLED.show();
delay(500);
leds[1] = CRGB::White; //
FastLED.show();
delay(500);
leds[0] = CRGB::White; //
FastLED.show();
delay(2000);
digitalWrite(outputPin, LOW); // Turn off output on pin A5
}
// Turn off all LEDs (set to black)
void turnOffLEDs() {
fill_solid(leds, LED_COUNT, CRGB::Black);
FastLED.show();
}
// FastLED Rainbow pattern
void RainbowPattern() {
uint8_t wait = 20;
for (int j = 0; j < 256; j++) {
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CHSV((i * 256 / LED_COUNT) + j, 255, 255);
}
FastLED.show();
delay(wait);
}
}
// FastLED Rainbow with Glitter pattern
void RainbowWithGlitterPattern() {
uint8_t wait = 20;
for (int j = 0; j < 256; j++) {
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CHSV((i * 256 / LED_COUNT) + j, 255, 255);
}
addGlitter(80); // Add glitter effect
FastLED.show();
delay(wait);
}
}
// FastLED Confetti pattern
void ConfettiPattern() {
fadeToBlackBy(leds, LED_COUNT, 10);
int pos = random16(LED_COUNT);
leds[pos] += CHSV(random8(), 255, 192);
FastLED.show();
delay(20);
}
// FastLED SineLon pattern
void SineLonPattern() {
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, LED_COUNT, 20);
//uint8_t gHue = 0; // rotatin "base color" used by many of the patterns
int pos = beatsin16(13,0,LED_COUNT);
leds[pos] += CHSV( gHue, 255, 192);
FastLED.show();
}
// FastLED Fire2012 pattern
void Fire2012Pattern() {
static byte heat[NUM_LEDS];
for (int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
for (int k = NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
if (random8() < SPARKING) {
int y = random8(10); // Adjust the range as needed
heat[y] = qadd8(heat[y], random8(160, 255));
}
for (int j = 0; j < NUM_LEDS; j++) {
CRGB color = HeatColor(heat[j]);
int pixelnumber;
if (gReverseDirection) {
pixelnumber = (NUM_LEDS - 1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
FastLED.show();
}
void addGlitter(fract8 chanceOfGlitter) {
if (random8() < chanceOfGlitter) {
leds[random16(LED_COUNT)] += CRGB::White;
}
}