// https://www.reddit.com/r/FastLED/comments/1am4bn5/trouble_wrapping_around_a_ring_with_crgbset/
#include <FastLED.h>
#define DATA_PIN PB1
#define NUM_LEDS 99
#define BRIGHTNESS 255
CRGB realLEDS[NUM_LEDS];
CRGBSet leds(realLEDS, NUM_LEDS);
const long outerInterval = 20;
int dot = 0;
int increment = 12;
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setCorrection(TypicalPixelString);
FastLED.setBrightness(BRIGHTNESS);
}
void loop()
{
EVERY_N_MILLIS(outerInterval) {
FastLED.clear();
safe_fill(dot, dot+increment, CRGB::Blue);
safe_fill(dot+increment*2, dot+increment*3, CRGB::Blue);
safe_fill(dot+increment*4, dot+increment*5, CRGB::Blue);
safe_fill(dot+increment*6, dot+increment*7, CRGB::Blue);
FastLED.show();
if (++dot >= NUM_LEDS) dot = 0;
}
}
void safe_fill(int p_start, int p_end, CRGB colour) {
// constrain the start and end positions to the length of the array
p_start %= NUM_LEDS;
p_end %= NUM_LEDS;
if (p_end >= p_start) {
// the whole fill fits within the leds[] array
leds(p_start, p_end) = colour;
} else {
// the fill wraps, so fill the head...
leds(p_start, NUM_LEDS - 1) = colour;
// ...and the tail separately
leds(0, p_end) = colour;
}
}