/*************************************************************************
Make sure to include the Adafruit NeoPixel library for ESP32 before
compiling and uploading the code. Also, adjust the RING1_PIN and
RING2_PIN constants according to the GPIO pins you're using to
connect the NeoPixel rings.
The code includes two functions: chaseAnimation() for the clockwise
and anticlockwise chasing animation, and blinkColors() for the
blinking animation with different colors. The loop() function
controls the overall animation pattern by calling these functions
for both rings. The animation cycles are repeated three times
for each ring.
Please note that this code assumes you have already
installed the Adafruit NeoPixel library and have the
necessary connections set up for the NeoPixel rings.
author arvind patil 16 may23
*****************************************************************/
#include <Adafruit_NeoPixel.h>
#define RING1_PIN 2
#define RING1_LED_COUNT 24
#define RING2_PIN 4
#define RING2_LED_COUNT 24
Adafruit_NeoPixel ring1(RING1_LED_COUNT, RING1_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ring2(RING2_LED_COUNT, RING2_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
ring1.begin();
ring2.begin();
}
void loop() {
chaseAnimation(ring1, true); // Clockwise chase animation for ring1
chaseAnimation(ring1, false); // Anti-clockwise chase animation for ring1
blinkColors(ring1, 3); // Blink animation for ring1
chaseAnimation(ring2, true); // Clockwise chase animation for ring2
chaseAnimation(ring2, false); // Anti-clockwise chase animation for ring2
blinkColors(ring2, 3); // Blink animation for ring2
}
void chaseAnimation(Adafruit_NeoPixel& ring, bool clockwise) {
uint32_t color = ring.Color(random(256), random(256), random(256)); // Random RGB color
int startLed = clockwise ? 0 : ring.numPixels() - 1;
int endLed = clockwise ? ring.numPixels() - 1 : 0;
int increment = clockwise ? 1 : -1;
for (int i = startLed; i != endLed + increment; i += increment) {
ring.setPixelColor(i, color);
ring.show();
delay(50);
ring.setPixelColor(i, 0); // Turn off the LED
}
}
void blinkColors(Adafruit_NeoPixel& ring, int blinkCount) {
uint32_t colors[] = {ring.Color(255, 0, 0), ring.Color(0, 255, 0), ring.Color(0, 0, 255), ring.Color(0, 255, 255)};
for (int i = 0; i < blinkCount; i++) {
for (const auto& color : colors) {
for (int j = 0; j < ring.numPixels(); j++) {
ring.setPixelColor(j, color);
}
ring.show();
delay(200);
for (int j = 0; j < ring.numPixels(); j++) {
ring.setPixelColor(j, 0); // Turn off all LEDs
}
ring.show();
delay(200);
}
}
}