#define N_LEDS 29 #define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800); int recColor1 = 3; int recColor2 = 2; int recColor3 = 1; int blinkDelay = 0; int mCounter = 0; const int REPS = 1000; // Number of times to repeat the animation loop (1-255) int rep = REPS;
void setup() { strip.begin(); randomSeed(analogRead(0)); }
int pos = 0, dir = 1; // Position, direction of "eye" int pos1 = 0, dir1 = 1; // Position, direction of "eye" int pos2 = 0, dir2 = -1; // Position, direction of "eye"
void loop() {
mCounter++;
if (mCounter<100) {
Scanner1();
} else if (mCounter > 99 && mCounter < 200) {
Scanner1();
} else if (mCounter > 199 && mCounter < 400) {
Scanner1();
} else if (mCounter > 399 && mCounter < 600) {
Scanner1();
} else if (mCounter > 599 && mCounter < 990) {
Scanner1();
//mRandom();
} else {
mRedEyes();
}
if (mCounter>1000) {
mCounter = 0;
strip.clear();
}
}
void mRedEyes() {
eyeDisplay();
strip.show();
delay(1000);
strip.clear();
strip.show();
blinkDelay = random(220) + 30;
delay(blinkDelay);
}
void eyeDisplay() { strip.setPixelColor(7, 0x100000); // Dark blue strip.setPixelColor(8, 0x800000); // Medium blue strip.setPixelColor(9 , 0xFF3000); // Center pixel is brightest strip.setPixelColor(10, 0x800000); // Medium blue strip.setPixelColor(11, 0x100000); // Dark blue
strip.setPixelColor(16, 0x100000); // Dark blue
strip.setPixelColor(17, 0x800000); // Medium blue
strip.setPixelColor(18, 0xFF3000); // Center pixel is brightest
strip.setPixelColor(19, 0x800000); // Medium blue
strip.setPixelColor(20, 0x100000); // Dark blue
}
void mRandom() {
for(int x=0; x<N_LEDS;x++) {
recColor1 = random(255);
recColor2 = random(255);
recColor3 = random(255);
strip.setPixelColor(x, recColor1,recColor2,recColor3);
}
strip.show();
delay(20);
}
void Scanner1() { int j; strip.setPixelColor(pos - 2, 0x000010); // Dark blue strip.setPixelColor(pos - 1, 0x400040); // Medium blue strip.setPixelColor(pos , 0xFF3000); // Center pixel is brightest strip.setPixelColor(pos + 1, 0x400040); // Medium blue strip.setPixelColor(pos + 2, 0x000010); // Dark blue
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 < 0) {
pos = 1;
dir = -dir;
} else if(pos >= strip.numPixels()) {
pos = strip.numPixels() - 2;
dir = -dir;
}
}