Skip to content

Instantly share code, notes, and snippets.

@morphatic
Created August 23, 2015 22:01
Show Gist options
  • Save morphatic/5ed29ff87b906f2a1256 to your computer and use it in GitHub Desktop.
Save morphatic/5ed29ff87b906f2a1256 to your computer and use it in GitHub Desktop.
Modification of the cylon script from https://learn.adafruit.com/larson-scanner-shades/software that allows the start position on the strip to be specified.
#include <Adafruit_NeoPixel.h>
#define PIN 1
#define N_LEDS 100
#define START 50
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
}
int pos = START, dir = 1; // Position, direction of "eye"
void loop() {
int j;
// Draw 5 pixels centered on pos. setPixelColor() will clip any
// pixels off the ends of the strip, we don't need to watch for that.
strip.setPixelColor(pos - 2, 0x100000); // Dark red
strip.setPixelColor(pos - 1, 0x800000); // Medium red
strip.setPixelColor(pos , 0xFF3000); // Center pixel is brightest
strip.setPixelColor(pos + 1, 0x800000); // Medium red
strip.setPixelColor(pos + 2, 0x100000); // Dark red
strip.show();
delay(30);
// Rather than being sneaky and erasing just the tail pixel,
// it's easier to erase it all and draw a new one next time.
for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
// Bounce off ends of strip
pos += dir;
if(pos < START) {
pos = START;
dir = -dir;
} else if(pos >= strip.numPixels() + START) {
pos = strip.numPixels() + START - 2;
dir = -dir;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment