#include <FastLED.h>
#define LED_PIN 6 // Pin connected to the LED data input
#define NUM_LEDS 40 // Total number of LEDs in the strip
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB // Color order of the LED strip (typically GRB for WS2812B)
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(100); // Set initial brightness (0-255)
}
void loop() {
static uint8_t startIndex = 0; // Start index for the chaser effect
// Update all LEDs
for (int i = 0; i < NUM_LEDS; i++) {
// Determine brightness based on distance from the current position
int distance = abs(startIndex - i);
int brightness = 255 - map(distance, 0, NUM_LEDS / 2, 0, 255); // Map distance to brightness range
// Set color with fading tail
leds[i] = CRGB(brightness, brightness, brightness);
}
FastLED.show(); // Update the LED strip with the new colors
// Move the chaser effect forward smoothly
startIndex = (startIndex + 1) % NUM_LEDS;
// Delay to control the speed of the chaser effect (approximately 1.5 seconds per cycle)
delay(100 / NUM_LEDS);
}