Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 7 //6 for testing, 7 for production
- #define COLOR_ORDER GRB
- #define CHIPSET WS2811
- #define NUM_LEDS 300 //88 for testing, 300 for prodction
- #define BRIGHTNESS 50
- #define FRAMES_PER_SECOND 30
- bool gReverseDirection = false;
- int lifespan = 30;
- int totalShells = 0;
- const long interval = 1000 / FRAMES_PER_SECOND;
- unsigned long previousMillis = 0;
- CRGB leds[NUM_LEDS];
- class FireworkShell {
- int stringPos; //origin of the blast
- int age; //how long the blast has been on the string
- int maxLife; //how old this one can get
- uint8_t hue; //color of the shell
- public:
- FireworkShell(int xPos, int howOld, int deathAge, uint8_t shellColor) {
- stringPos = xPos;
- age = howOld;
- maxLife = deathAge;
- hue = shellColor;
- }
- void Update() {
- if (age < maxLife) {
- int newPosR = stringPos + age;
- int newPosL = stringPos - age;
- if (newPosR < NUM_LEDS) leds[newPosR] += CHSV(hue, 255, 255);
- if (newPosL >= 0) leds[newPosL] += CHSV(hue, 255, 255);
- if (age > 0) {
- int tailR = newPosR - 1;
- int tailL = newPosL + 1;
- if (tailR > 0 && tailR < NUM_LEDS) {
- leds[tailR] = CHSV(hue+23, random(0, 128), random(0, 200));
- }
- if (tailL > 0 && tailL < NUM_LEDS) {
- leds[tailL] = CHSV(hue+23, random(0, 128), random(0, 200));
- }
- }
- }
- if (age < maxLife + 20) {
- age++;
- } else {
- age = 0;
- hue=random(0,213);
- maxLife = random(5, lifespan);
- stringPos = random(0, NUM_LEDS);
- //Serial.println(maxLife);
- }
- }
- };
- FireworkShell shell1(random(0, NUM_LEDS), 0, random(5, lifespan), 171);
- FireworkShell shell2(random(0, NUM_LEDS), 0, random(5, lifespan), 0);
- FireworkShell shell3(random(0, NUM_LEDS), 0, random(5, lifespan), 85);
- FireworkShell shell4(random(0, NUM_LEDS), 0, random(5, lifespan), 85);
- FireworkShell shell5(random(0, NUM_LEDS), 0, random(5, lifespan), 0);
- void setup() {
- Serial.begin(9600);
- delay(3000); // sanity delay
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
- randomSeed(analogRead(0));
- };
- void loop() {
- EVERY_N_MILLISECONDS(20) {
- fadeToBlackBy(leds, NUM_LEDS, 30);
- shell1.Update();
- shell2.Update();
- shell3.Update();
- shell4.Update();
- shell5.Update();
- FastLED.show();
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment