// PL9823 Knight Night // November 2015 // Creative Common License // www.0lab.it #include // SETUP YOUR OUTPUT PIN AND NUMBER OF PIXELS #define PIN 6 #define NUM_PIXELS 5 #define vel 100 // Velocity in milliseconds Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_RGB + NEO_KHZ400); void setup() { strip.begin(); clearStrip(); // Initialize all pixels to 'off' delay(1000); } void loop() { knightRider(3, vel, 4, 0xFF1000); // Cycles, Speed, Width, RGB Color (original orange-red) knightRider(3, vel, 3, 0xFF00FF); // Cycles, Speed, Width, RGB Color (purple) knightRider(3, vel, 2, 0x0000FF); // Cycles, Speed, Width, RGB Color (blue) knightRider(3, vel, 5, 0xFF0000); // Cycles, Speed, Width, RGB Color (red) knightRider(3, vel, 6, 0x00FF00); // Cycles, Speed, Width, RGB Color (green) knightRider(3, vel, 7, 0xFFFF00); // Cycles, Speed, Width, RGB Color (yellow) knightRider(3, vel, 8, 0x00FFFF); // Cycles, Speed, Width, RGB Color (cyan) knightRider(3, vel, 2, 0xFFFFFF); // Cycles, Speed, Width, RGB Color (white) clearStrip(); delay(2000); // Iterate through a whole rainbow of colors for(byte j=0; j<252; j+=7) { knightRider(1, vel, 2, colorWheel(j)); // Cycles, Speed, Width, RGB Color } clearStrip(); delay(2000); } // Cycles - one cycle is scanning through all pixels left then right (or right then left) // Speed - how fast one cycle is (32 with 16 pixels is default KnightRider speed) // Width - how wide the trail effect is on the fading out LEDs. The original display used // light bulbs, so they have a persistance when turning off. This creates a trail. // Effective range is 2 - 8, 4 is default for 16 pixels. Play with this. // Color - 32-bit packed RGB color value. All pixels will be this color. // knightRider(cycles, speed, width, color); void knightRider(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; count0; x--) { old_val[x-1] = dimColor(old_val[x-1], width); strip.setPixelColor(x-1, old_val[x-1]); } strip.show(); delay(speed); } for (int count = NUM_PIXELS-1; count>=0; count--) { strip.setPixelColor(count, color); old_val[count] = color; for(int x = count; x<=NUM_PIXELS ;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