Skip to content

Instantly share code, notes, and snippets.

@assimilat
Created February 6, 2022 03:59
Show Gist options
  • Select an option

  • Save assimilat/27f80b508293918884b901c11ad23ca2 to your computer and use it in GitHub Desktop.

Select an option

Save assimilat/27f80b508293918884b901c11ad23ca2 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
// SETUP YOUR OUTPUT PIN AND NUMBER OF PIXELS
#define PIN 6
#define NUM_PIXELS 50
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
clearStrip(); // Initialize all pixels to 'off'
delay(1000);
}
void loop() {
ledChase(1, 40, 8, 0x00FF00); // Cycles, Speed, Width, RGB Color (green)
ledChase(1, 40, 8, 0xFFFF3F); // Cycles, Speed, Width, RGB Color (white)
clearStrip();
}
void ledChase(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) {
uint32_t old_val[NUM_PIXELS]; // up to 256 lights!
// Larson time baby!
for(int i = 0; i < cycles; i++){
for (int count = 1; count<NUM_PIXELS; count++) {
strip.setPixelColor(count, color);
old_val[count] = color;
for(int x = count; x>0; x--) {
old_val[x-1] = dimColor(old_val[x-1], width);
strip.setPixelColor(x-1, old_val[x-1]);
}
strip.show();
delay(speed);
}
}
}
void clearStrip() {
for( int i = 0; i<NUM_PIXELS; i++){
strip.setPixelColor(i, 0x000000); strip.show();
}
}
uint32_t dimColor(uint32_t color, uint8_t width) {
return (((color&0xFF0000)/width)&0xFF0000) + (((color&0x00FF00)/width)&0x00FF00) + (((color&0x0000FF)/width)&0x0000FF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment