#include <Adafruit_NeoPixel.h>
#define LED_PIN 6 // Pin connected to the NeoPixels
#define LED_COUNT 60 // Number of NeoPixels in the ring
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long startTime; // Start time of the animation
//unsigned long duration = 3600000; // Duration of the animation in milliseconds
unsigned long duration = 1000; // Duration of the animation in milliseconds
unsigned long animationStartTime; // Start time of the animation
unsigned long animationDuration = 5000; // Duration of the animation in milliseconds
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
//delay(500); // Delay for visual effect
startTime = millis(); // Record the start time
animationStartTime = millis(); // Record the start time
}
void loop() {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
if (elapsedTime <= duration) {
// Calculate the percentage of completion
float percentage = (float)elapsedTime / duration;
// Calculate the number of LEDs to light up
int numLeds = (int)(percentage * LED_COUNT);
// Turn on the LEDs up to 'numLeds'
for (int i = 0; i < numLeds; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 255)); // Set color to white (full brightness)
}
strip.show(); // Update the strip with the new colors
} else {
performAnimation(); // Rainbow Animation after the ring fills up
}
}
void performAnimation() {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - animationStartTime;
// Calculate the percentage of completion
float percentage = (float)elapsedTime / animationDuration;
float fadePercentage = 20; // Fade speed for the black to color transition
// Calculate the number of LEDs to light up
int numLeds = (int)(percentage * LED_COUNT);
// Set the color of each LED based on its position in the rainbow
for (int i = 0; i < LED_COUNT; i++) {
int hue = (int)(currentTime / 10 + i * 256 / LED_COUNT) % 256;
int fadeValue = (int)(255 * (percentage - fadePercentage));
if (fadeValue < 0) fadeValue = 0;
if (i < numLeds) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue * 65536L / 256)));
} else {
strip.setPixelColor(i, strip.gamma32(strip.Color(0, 0, 0, fadeValue)));
}
}
strip.show(); // Update the strip with the new colors
if (elapsedTime >= animationDuration) {
// Reset animation and continue
animationStartTime = currentTime;
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT