Skip to content

Instantly share code, notes, and snippets.

@tprochazka
Last active January 12, 2016 22:40
Show Gist options
  • Save tprochazka/566194461c76106499bd to your computer and use it in GitHub Desktop.
Save tprochazka/566194461c76106499bd to your computer and use it in GitHub Desktop.
Simplistic Knight Rider (KIT) lights implementation
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define LEDS 9
#define SUBSTEPS 8
#define DELAY 75
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_RGB + NEO_KHZ800);
int position = 0;
int substep;
boolean dirRight = true;
double leds[LEDS];
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(128);
}
void loop() {
leds[position] = 255;
for (int j = 0; j < SUBSTEPS; j++) {
for(int i = 0; i < strip.numPixels(); i++) {
leds[i] = leds[i]/1.03;
strip.setPixelColor(i, strip.Color(leds[i]+1,0,0));
}
strip.show();
delay(DELAY/SUBSTEPS);
}
if (dirRight) {
position++;
} else {
position--;
}
if (position == strip.numPixels()-1 || position == 0) {
dirRight = !dirRight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment