#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 2
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 64
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 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)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
// setup() function -- runs once at startup --------------------------------
void knightRider1() { Serial.println("loop0"); }
//void knightRider2() { Serial.println("loop1"); }
//void loop2() { Serial.println("loop2"); }
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
//#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
// clock_prescale_set(clock_div_1);
//#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
Serial.begin(9600);
}
void loop() {
//loop0(); delay(1000); // for testing only
knightRider1(strip.Color(255, 0, 0), 100, 5); // Red Bar
//knightRider2(strip.Color(255, 127, 0), 500, 7); // Red Bar
// loop1(); delay(500); // for testing only
//loop2(); delay(100); // for testing only
}
void knightRider1(uint32_t color, int wait, int barLength) {
uint32_t off = (0, 0, 0);
int i=0;
int j=0;
int k=0;
int i2=0;
int j2=0;
int k2=0;
while(i<strip.numPixels()) {
for(int k=0; k<barLength; k++) {
strip.setPixelColor(k, color); // Set pixel's color (in RAM)
int k2 = LED_COUNT - k;
strip.setPixelColor(k2, color);
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
for(int j=0; j>barLength; j++) {
strip.setPixelColor(j, off); // Set Bar Pixel 1 to 0 (in RAM)
strip.setPixelColor(j+barLength, color); // Set next Bar pixel to color (in RAM)
int j2 =LED_COUNT - j;
strip.setPixelColor(j2, off);
strip.setPixelColor(j2-barLength, color);
strip.show();
//}
//for(int j2=strip.numPixels(); j2>0; j2--) {
/// strip.setPixelColor(j2, off); // Set Bar Pixel 1 to 0 (in RAM)
// strip.setPixelColor(j2-barLength, color); // Set next Bar pixel to color (in RAM)
// strip.show(); // Update strip to match
delay(wait);
}
for(int k=strip.numPixels(); k>strip.numPixels()- barLength; k--) {
strip.setPixelColor(k, color); // Set pixel's color (in RAM)
int k2 = LED_COUNT - k;
strip.setPixelColor(k2, color);
strip.show(); // Update strip to match
//}
//for(int k2=0; k2<barLength; k2++) {
//strip.setPixelColor(k2, color); // Set pixel's color (in RAM)
//strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
for(int j=strip.numPixels(); j>barLength; j--) {
strip.setPixelColor(j, off); // Set Bar Pixel 1 to 0 (in RAM)
strip.setPixelColor(j-barLength, color);
int j2 = LED_COUNT - j;
strip.setPixelColor(j2, off);
strip.setPixelColor(j2+barLength, color);
// Set next Bar pixel to color (in RAM)
strip.show(); // Update strip to match
// Update strip to match
delay(wait);
}
}
}