Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ghostbusters Ecto Scarf
// Note: Based on Meteor Rain example sketch found in Tweaking4All.com from Using Neopixels guide.
//
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 28
#define PIN 9
#define PIN1 10
#define PIN2 6
#define BRIGHTNESS 40
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRB + NEO_KHZ800);
void setup() {
//Serial.begin(9600);
//Serial.println("DHT22 on board!");
strip.begin();
strip1.begin();
strip2.begin();
strip.setBrightness(BRIGHTNESS);
strip1.setBrightness(BRIGHTNESS);
strip2.setBrightness(BRIGHTNESS);
strip.show();
strip1.show();
strip2.show();
randomSeed(analogRead(0));
}
//============================================================
void loop(){
byte rr = 0xff;
byte gg = 0xff;
byte bb = 0xff;
/////////////////////////////////
int zz = random(1,6);
bool fire = false;
//Serial.println(zz);
if( zz != 5){
rr = 0x00;
gg = 0xff;
bb = 0x00;
fire = true;
}
else {
rr = 0xff;
gg = 0x45;
bb = 0x00;
}
meteorRain(fire,random(1,4), rr, gg, bb, random(4,9), random(64,75), true, random(25,65));
// meteorRain(channels, byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
//////////////////////////////////
delay(random(1100));
}
//============================================================
//============================================================
void meteorRain(bool firex, int rx, byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack( rx, j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(rx, i-j, red, green, blue);
if(firex != true){setPixel(rx,i-j,0xFF,0x00,0xFF);
showStrip();
delay(9);
setPixel(rx,i-j,0xFF,0xFF,0xFF);
showStrip();
delay(10);
setPixel(rx,i-j,0,0,0xFF);
showStrip();
delay(12);}
else {setPixel(rx,i-j,0xFF,0xFF,0xFF);
showStrip();
delay(17);}
setPixel(rx, i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int rxx, int ledNo, byte fadeValue) {
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
switch(rxx){
case 1:
strip.setPixelColor(ledNo, r,g,b);
strip1.setPixelColor(ledNo, r,g,b);
break;
case 2:
strip1.setPixelColor(ledNo, r,g,b);
strip2.setPixelColor(ledNo, r,g,b);
break;
case 3:
strip.setPixelColor(ledNo, r,g,b);
strip2.setPixelColor(ledNo, r,g,b);
break;
default:
strip.setPixelColor(ledNo, r,g,b);
strip1.setPixelColor(ledNo, r,g,b);
strip2.setPixelColor(ledNo, r,g,b);
break;
}
}
void showStrip() {
strip.show();
strip1.show();
strip2.show();
}
void setPixel(int rxxx, int Pixel, byte red, byte green, byte blue) {
switch (rxxx){
case 1:
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
strip1.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
case 2:
strip1.setPixelColor(Pixel, strip.Color(red, green, blue));
strip2.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
case 3:
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
strip2.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
default:
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
strip1.setPixelColor(Pixel, strip.Color(red, green, blue));
strip2.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
}
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
strip.setPixelColor(i, strip.Color(red, green, blue));
strip1.setPixelColor(i, strip.Color(red, green, blue));
strip2.setPixelColor(i, strip.Color(red, green, blue));
}
showStrip();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment