#include <FastLED.h>
#define NUM_LEDS 60 // Number of LEDs in the strip
#define DATA_PIN 2 // Data pin for the LED strip
#define WAVE_WIDTH 50 // Number of LEDs lit in the wave
CRGB leds[NUM_LEDS]; // Array to hold the LED colors
// Function to create a wave effect with variable brightness
void wavePattern(CRGB color, int speed, int direction) {
static int position = 0; // Keeps track of wave position
// Clear the LED strip
fill_solid(leds, NUM_LEDS, CRGB::Black);
// Create a wave with WAVE_WIDTH number of LEDs lit at the same time
for (int i = -WAVE_WIDTH/2; i <= WAVE_WIDTH/2; i++) {
int ledPos = position + i;
// Wrap the position around if it goes out of bounds
if (ledPos >= NUM_LEDS) ledPos -= NUM_LEDS;
if (ledPos < 0) ledPos += NUM_LEDS;
// Calculate brightness, with the center LED being the brightest
uint8_t brightness = 255 - abs(i) * (255 / (WAVE_WIDTH / 2 + 1));
// Set the color with the adjusted brightness
leds[ledPos] = color;
leds[ledPos].fadeLightBy(255 - brightness);
}
// Show the updated LED colors
FastLED.show();
// Update the position based on the direction
if (direction == 1) {
position++;
if (position >= NUM_LEDS) position = 0;
} else {
position--;
if (position < 0) position = NUM_LEDS - 1;
}
// Control the speed of the wave
delay(speed);
}
void setup() {
// Initialize the LED strip
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
}
void loop() {
// Call wavePattern with customizable parameters
wavePattern(CRGB::Green, 20, 1); // Blue color, speed of 50ms, forward direction
}