FastLED Glitter

I have cobbled together something that works perfectly for what it is.
I have 2 PIR sensors on my staircase. If I go up then I get a nice effect as the stairs are lit one at a time. They stay on for 35 seconds then turn off in the same manner.
Going down does the same but with the flow in reverse.

#include <FastLED.h>
#define NUM_LEDS 120
#define DATA_PIN 3
#define CLOCK_PIN 12
CRGB leds[NUM_LEDS];
int LED = 13; // the pin that the LED is atteched to
int PIR = 2; // the pin that the sensor is atteched to
int PIR_UP = 4; // the pin that the sensor is atteched to

void setup() {
pinMode(LED, OUTPUT); // initalize LED as an output
pinMode(PIR, INPUT); // initialize sensor as an input
pinMode(PIR_UP, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}

void loop(){
int i;
int t;
int x;
int numleds;

FastLED.addLeds<WS2811, DATA_PIN, BRG>(leds, NUM_LEDS);
if (digitalRead(PIR) == HIGH) { // check if the sensor is HIGH

numleds = NUM_LEDS;
for(int whiteLed = 0; whiteLed < numleds; whiteLed = whiteLed + 1) {
leds[whiteLed] = CRGB(200,200,200);
FastLED.show();
delay(30);
}
delay(35000); // seconds to stay on

for(int whiteLed = 0; whiteLed < numleds; whiteLed = whiteLed + 1) {
leds[whiteLed] = CRGB::Black;
FastLED.show();
delay(30);
}
}

else if (digitalRead(PIR_UP) == HIGH) { // check if the sensor is HIGH

numleds = NUM_LEDS;
for(int whiteLed = 120; whiteLed > 0; whiteLed = whiteLed - 1) {
leds[whiteLed] = CRGB(200,200,200);
FastLED.show();
delay(30);
}
delay(35000); // seconds to stay on

for(int whiteLed = 120; whiteLed > 0; whiteLed = whiteLed - 1) {
leds[whiteLed] = CRGB::Black;
FastLED.show();
delay(30);
}

}
}

I'm trying to add the addGlitter() function from the FastLED demo reel to have the glitter effect for the 35 seconds that the lights stay on for but I just cannot get any of my bumbling attempts to compile.

Can anyone help please?

Your sketch is going to do NOTHING for those 35 seconds. If you want something to happen, change this to a timing loop:

    unsigned long startTime = millis();
    while (millis() - startTime < 35000ul)
    {
      // Do the glitter effect here
    }

And when the glitter is working, increase your insurance…
Epileptics and migraine sufferers will thank you later.

1 Like