#include <Adafruit_NeoPixel.h>
#define LED_PIN 22 // Pin connected to the data input of the LED ring
#define NUM_LEDS 16 // Number of LEDs in the ring
Adafruit_NeoPixel ring(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize the LED ring
ring.begin();
ring.show(); // Initialize all pixels to 'off'
Serial.begin(115200); // Start serial communication
}
void loop() {
// Example 1: Color wipe effect
colorWipe(ring.Color(255, 0, 0), 50); // Red color wipe
delay(500);
colorWipe(ring.Color(0, 255, 0), 50); // Green color wipe
delay(500);
colorWipe(ring.Color(0, 0, 255), 50); // Blue color wipe
delay(500);
// Example 2: Rainbow effect
rainbow(20); // Display rainbow with a delay of 20ms between frames
delay(500);
}
// Fill the entire ring with one color, one pixel at a time
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < ring.numPixels(); i++) {
ring.setPixelColor(i, color);
ring.show();
delay(wait);
}
}
// Fill the ring with a moving rainbow
void rainbow(int wait) {
int firstPixelHue = 0; // Start at 0 degrees of hue
for (int i = 0; i < ring.numPixels(); i++) {
int pixelHue = firstPixelHue + (i * 65536L / ring.numPixels());
ring.setPixelColor(i, ring.ColorHSV(pixelHue));
}
ring.show();
delay(wait);
firstPixelHue += 256; // Increment the hue for the next frame
}