I’m using FastLED library to eventually create a comet animation, where another comet get incrementally added as an event happens.
I’m starting out trying to do a simpler chase animation first with a single comet.
Why is it that I can’t make the comet tail longer? If I try to set the color of “leds[-7]”, the program crashes. So I’m stuck with making the comet only 5 LEDS long.
#Here is my code:
//================================================
// This #include statement was automatically added by the Particle IDE.
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define LED_COUNT 144
#define LED_PIN D1
// Block of memory that will be used for storing and manipulating the led data.
// This sets up an array that we can manipulate to set/clear led data
struct CRGB leds[LED_COUNT];
uint8_t hue = 32;
//================================================
// Now, let's actually set up our leds.
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);
// This tells the library that there's a strand of ws2812b NEOPIXELs on pin D1,
// and those leds will use the led array leds, and there are LED_COUNT (aka 144) of them.
LEDS.addLeds<WS2812B, LED_PIN>(leds, LED_COUNT);
LEDS.setBrightness(200);
FastLED.clear();
FastLED.show();
}
void loop(){
meteorShower();
}
void meteorShower(){
for(uint16_t i=0; i<LED_COUNT+6; i++) {
leds[i-1] = CHSV(0, 0, 100); // Draw new pixel
leds[i-2] = CHSV((hue - 20), 255, 210);
leds[i-3] = CHSV((hue - 22), 255, 180);
leds[i-4] = CHSV((hue - 25), 255, 90);
leds[i-5] = CHSV((hue - 28), 140, 40);
leds[i-6] = CRGB::Black; // Erase pixel a few steps back
FastLED.show();
delay(50);
};
}