#include "FastLED.h"
const size_t NUM_LEDS = 28;
CRGB leds[NUM_LEDS];
CRGB background[NUM_LEDS];
const uint8_t basesStart[] = { 5, 10, 15, 20 };
const uint8_t basesLength = 3;
const uint8_t basesCount = sizeof( basesStart ) / sizeof( basesStart[0] );
void setup()
{
FastLED.addLeds< WS2812, 6, GRB >( leds, NUM_LEDS );
FastLED.setBrightness( 50 );
fill_gradient_RGB( leds, NUM_LEDS, CRGB::Magenta, CRGB::Yellow );
memcpy( background, leds, sizeof( background ) );
for ( uint8_t i = 0; i < basesCount; i++ )
{
for ( uint8_t j = basesStart[i], k = j + basesLength; j < k; j++ )
{
leds[j] = CRGB::White;
}
}
FastLED.show();
delay( 2000 );
}
void loop()
{
uint32_t now = millis();
static uint32_t past = now;
if ( now - past >= 1000UL )
{
past = now;
static int8_t offset = 0;
for ( uint8_t i = 0; i < basesCount; i++ )
{
for ( uint8_t j = basesStart[i] + offset, k = j + basesLength; j < k; j++ )
{
leds[j] = background[j];
}
}
offset = offset == 3 ? -3 : 3;
for ( uint8_t i = 0; i < basesCount; i++ )
{
for ( uint8_t j = basesStart[i] + offset, k = j + basesLength; j < k; j++ )
{
leds[j] = CRGB::White;
}
}
FastLED.show();
}
}