Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WS2812B LED Runway Lights
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 9
#define MAGINT 0
#define PHASES 6
#define NUMPIXELS 300
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 25;
void setup() {
pinMode(PIN, OUTPUT);
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
uint8_t r,g,b;
uint32_t c;
uint16_t i, j, phase, pixel;
for(i = 0; i < NUMPIXELS; i++){
for(j = 0; j < NUMPIXELS; j++){
// Fade all the pixels
c = pixels.getPixelColor(j);
r = (uint8_t)(c >> 16),
g = (uint8_t)(c >> 8),
b = (uint8_t)c;
pixels.setPixelColor(j, pixels.Color(max(r - 3, 0), max(g - 2, 0), max(b - 1, 0))); // Fade R and G channels faster for a blue ghost trail
}
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
for(phase = 0; phase < PHASES; phase++) {
pixel = NUMPIXELS / PHASES * phase + i;
pixels.setPixelColor(circle(pixel, true), pixels.Color(50,50,50));
}
pixels.show(); // Push the next frame
delay(delayval);
}
}
int circle(int pos, boolean flip) {
pos = pos >= NUMPIXELS ? pos - NUMPIXELS : pos;
if(flip) {
pos = NUMPIXELS - pos - 1;
}
return pos;
}
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.