#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 16
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // Initialize the NeoPixel library
}
void loop() {
// Right Chase for 5 seconds
rightChase(1);
// Left Chase for 5 seconds
leftChase(1);
// All-round Flash
allRoundFlash(5); // Flash 5 times
}
void rightChase(int seconds) {
int iterations = seconds * 20; // 20 iterations per second (50ms delay)
for (int j = 0; j < iterations; j++) {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(255, 0, 0)); // Red
pixels.show(); // Update
delay(50); // 50ms delay
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Off
}
}
}
void leftChase(int seconds) {
int iterations = seconds * 20; // 20 iterations per second (50ms delay)
for (int j = 0; j < iterations; j++) {
for (int i = NUMPIXELS - 1; i >= 0; i--) {
pixels.setPixelColor(i, pixels.Color(0, 0, 255)); // Blue
pixels.show(); // Update
delay(50); // 50ms delay
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Off
}
}
}
void allRoundFlash(int flashes) {
for (int j = 0; j < flashes; j++) {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 255)); // White
}
pixels.show(); // Update
delay(250); // 250ms delay
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Off
}
pixels.show(); // Update
delay(250); // 250ms delay
}
}