Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neopixel Meteor 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);
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);
//Serial.println(zz);
//change rgb hex values for different color random meteor
if( zz != 5){
rr = 0xff;
gg = 0xff;
bb = 0xff;
}
else {
rr = 0xff;
gg = 0x00;
bb = 0x00;
}
meteorRain(random(1,5), rr, gg, bb, random(2,8), random(64,75), true, random(25,75));
// meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
//////////////////////////////////
delay(random(2000));
}
//============================================================
//============================================================
void meteorRain(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);
}
}
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);
break;
case 2:
strip1.setPixelColor(ledNo, r,g,b);
break;
case 3:
strip2.setPixelColor(ledNo, r,g,b);
break;
case 4:
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));
break;
case 2:
strip1.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
case 3:
strip2.setPixelColor(Pixel, strip.Color(red, green, blue));
break;
case 4:
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();
}
@caitlinsdad

This comment has been minimized.

Copy link
Owner Author

caitlinsdad commented Jan 8, 2018

Arduino sketch for Meteor Scarf.
Uses Adafruit Neopixel library.
Adafruit Flora with Neopixel strips. 3 data pins used for strips wired in parallel on each pin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.