Skip to content

Instantly share code, notes, and snippets.

@andijcr
Last active September 2, 2015 11:35
Show Gist options
  • Save andijcr/90ee99f938298bec15ed to your computer and use it in GitHub Desktop.
Save andijcr/90ee99f938298bec15ed to your computer and use it in GitHub Desktop.
larson scanner with neopixel led strip. the gist is for each loop to decay al the leds in the strip, and then add a moving full-on led. example here: https://www.youtube.com/watch?v=htmgPjYIphI
#Using an Adafruit NeoPixel led strip http://www.adafruit.com/product/1138
#include <Adafruit_NeoPixel.h>
#define MAX_P 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAX_P, 6, NEO_GRB + NEO_KHZ800);
int li=0;
int direction=+1;
uint32_t Red=strip.Color(255, 0, 0);
uint32_t Blank=strip.Color(0, 0, 0);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
//decay
for(uint16_t i=0; i<MAX_P; i++) {
uint8_t r= (strip.getPixelColor(i)>>16) & 0xff;
r=(r*3)/5;
strip.setPixelColor(i, r, 0, 0);
}
strip.setPixelColor(li, Red);
if(li>(MAX_P-1)){
li=MAX_P;
direction=-1;
}else if(li<0){
li=-1;
direction=1;
}
li+=direction;
strip.show();
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment