#include <FastLED.h>
#define NUM_LEDS 49 // Neopixel ring with 12 LEDs
#define DATA_PIN 0 // Pin connected to the data input of the ring
#define LED_TYPE WS2812B // Neopixel rings use WS2812B
#define COLOR_ORDER GRB // Color order for Neopixel rings
CRGB leds[NUM_LEDS];
unsigned long previousMillis = 0; // Timer variable for delay
unsigned long currentMillis = 0; // To track time for switching colors
int switchInterval = 7000; // Initial delay of 7000ms (7 seconds)
int cycles = 0; // Count of how many color changes have happened
int cycleThreshold = 4; // Number of cycles after which the delay decreases
int decreaseAmount = 2000; // Amount by which to decrease the delay (in milliseconds)
bool colorToggle = false; // To track which color to show
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void loop() {
currentMillis = millis(); // Get the current time
// Check if the switch interval has passed
if (currentMillis - previousMillis >= switchInterval) {
previousMillis = currentMillis; // Reset the timer
colorToggle = !colorToggle; // Toggle color
cycles++; // Increment the cycle counter
// After every 'cycleThreshold' cycles, reduce the delay by 'decreaseAmount'
if (cycles >= cycleThreshold) {
cycles = 0; // Reset cycle counter
if (switchInterval > decreaseAmount) { // Prevent the delay from going too low
switchInterval -= decreaseAmount; // Reduce delay by 'decreaseAmount' milliseconds
}
}
}
// Set the color based on the toggle state
if (colorToggle) {
fill_solid(leds, NUM_LEDS, CRGB(175, 21, 83)); // Color 1
} else {
fill_solid(leds, NUM_LEDS, CRGB(40, 185, 115)); // Color 2
}
FastLED.show(); // Display the color
}