Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define stripPin 6
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- #define stripLength 88
- #define BRIGHTNESS 128
- byte shell1 = 1;
- byte shell2 = 0;
- int shell1pos = 0;
- int shell2pos = 0;
- uint8_t shell1start = random(10,80);
- uint8_t shell2start = random(10,80);
- uint8_t shell1hue = random(255);
- uint8_t shell2hue = random(255);
- uint8_t tailLength = 8;
- CRGB leds[stripLength];
- void setup() {
- Serial.begin(9600);
- randomSeed(analogRead(0));
- delay(3000); // 3 second delay for recovery
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
- // tell FastLED about the LED strip configurations
- FastLED.addLeds<LED_TYPE, stripPin, COLOR_ORDER>(leds, stripLength);
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- fireworks();
- }
- void fireworks(){
- //shell 1
- if(shell1==1){
- //light master shells in opposite directions at position if greater than 0 and less than total length
- if((shell1start+shell1pos)<stripLength) leds[(shell1start+shell1pos)] = CHSV(shell1hue, 255,255);
- if((shell1start-shell1pos)>0) leds[(shell1start-shell1pos)] = CHSV(shell1hue, 255,255);
- //lights secondary shell at halfway point
- int halfWay1 = stripLength-shell1start;
- if((shell1start+shell1pos)>halfWay1) shell2=1;
- //creates tail
- for (int t=1; t<=tailLength; t++){
- int front = shell1start+shell1pos-t;
- int back = shell1start-shell1pos+t;
- //if tail positions would overlap initial start position, don't show
- if(front>shell1start && front<stripLength) leds[front] = CHSV(shell1hue-40,255,random(40));
- if(back<shell1start && back>0) leds[back] = CHSV(shell1hue-40,255,random(40));
- }
- //if shell has reached the end of BOTH sides of strip, reset color and pick new position
- if((shell1start+shell1pos)+tailLength>=stripLength && (shell1start-shell1pos)-tailLength<=0){
- shell1start = random(10,80);
- shell1pos = 0;
- shell1hue = random(255);
- shell1=0;
- }else{
- //increase position
- shell1pos++;
- }
- }
- //shell2
- if(shell2==1){
- //light master shells in opposite directions at position if greater than 0 and less than total length
- if((shell2start+shell2pos)<stripLength) leds[(shell2start+shell2pos)] = CHSV(shell2hue, 255,255);
- if((shell2start-shell2pos)>0) leds[(shell2start-shell2pos)] = CHSV(shell2hue, 255,255);
- //lights secondary shell at halfway point
- int halfWay2 = stripLength-shell2start;
- if((shell2start+shell1pos)>halfWay2) shell1=1;
- //creates tail
- for (int t=1; t<=tailLength; t++){
- int front = shell2start+shell2pos-t;
- int back = shell2start-shell2pos+t;
- //if tail positions would overlap initial start position, don't show
- if(front>shell2start && front<stripLength) leds[front] = CHSV(shell2hue-40,255,random(40));
- if(back<shell2start && back>0) leds[back] = CHSV(shell2hue-40,255,random(40));
- }
- //if shell has reached the end of BOTH sides of strip, reset color and pick new position
- if((shell2start+shell2pos)+tailLength>=stripLength && (shell2start-shell2pos)-tailLength<=0){
- shell2start = random(10,80);
- shell2pos = 0;
- shell2hue = random(255);
- shell2=0;
- }else{
- //increase position
- shell2pos++;
- }
- }
- //display everything
- FastLED.show();
- FastLED.delay(30);
- //reset everything to black to prep for next position
- for(int j=0;j<stripLength;j++){leds[j] = CRGB::Black;}
- //sometimes there's a kink where not enough time is given to reset any given shell. this is a slam fix
- if(shell2==0 && shell1==0)shell1=1;
- }
Advertisement
Add Comment
Please, Sign In to add comment