/********************************************************************************
This code initializes two NeoPixel rings, one attached to Pin 3 and the
other attached to Pin 11. It then alternates between blinking RGB
colors on the first ring and a chasing animation on the second ring.
Each animation is displayed for half a second before switching
to the other animation.
authorarvind patil
**************************************************************************/
#include <Adafruit_NeoPixel.h>
#define PIN1 3
#define PIN2 11
#define NUM_LEDS 24
Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRB + NEO_KHZ800);
void setup() {
pixels1.begin();
pixels2.begin();
}
void loop() {
// blinking RGB colors on NeoPixel ring attached to Pin 3
for (int i = 0; i < NUM_LEDS; i++) {
if (i % 2 == 0) {
pixels1.setPixelColor(i, pixels1.Color(255, 0, 0)); // set red color for even numbered LEDs
} else {
pixels1.setPixelColor(i, pixels1.Color(0, 255, 0)); // set green color for odd numbered LEDs
}
}
pixels1.show(); // display the colors on the NeoPixel ring
delay(500); // wait 500 ms before changing colors
pixels1.clear(); // turn off all LEDs
delay(500); // wait another 500 ms before starting the loop again
// chasing LEDs on NeoPixel ring attached to Pin 11
for (int i = 0; i < NUM_LEDS; i++) {
pixels2.setPixelColor(i, pixels2.Color(255, 255, 0)); // set yellow color for all LEDs
pixels2.show(); // display the yellow color on the NeoPixel ring
delay(100); // wait 100 ms before moving to the next LED
pixels2.setPixelColor(i, pixels2.Color(0, 255, 0)); // set green color for the current LED
pixels2.setPixelColor((i + 1) % NUM_LEDS, pixels2.Color(0, 0, 0)); // turn off the next LED
pixels2.show(); // display the new colors on the NeoPixel ring
delay(100); // wait 100 ms before moving to the next LED
}
for (int i = NUM_LEDS - 1; i >= 0; i--) {
pixels2.setPixelColor(i, pixels2.Color(255, 255, 0)); // set yellow color for all LEDs
pixels2.show(); // display the yellow color on the NeoPixel ring
delay(100); // wait 100 ms before moving to the next LED
pixels2.setPixelColor(i, pixels2.Color(0, 255, 0)); // set green color for the current LED
pixels2.setPixelColor((i + 1) % NUM_LEDS, pixels2.Color(0, 0, 0)); // turn off the next LED
pixels2.show(); // display the new colors on the NeoPixel ring
delay(100); // wait 100 ms before moving to the next LED
}
}