// https://www.reddit.com/r/FastLED/comments/zdqvtq/pausing_beatsin16_at_0_and_resuming_from_0/

#include <FastLED.h>

#define NUM_LEDS 28
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, 3, GRB>(leds, NUM_LEDS);
}

void loop() {
  static uint32_t paused = 0;
  static uint32_t timebase = 0;
  static uint16_t lead_dot = 0;
  uint16_t prev_dot = lead_dot;

  if (!paused) {
    lead_dot = beatsin16(34, 0, NUM_LEDS - 1, timebase, 0);
  }
  fadeToBlackBy(leds, NUM_LEDS, 2);
  leds[lead_dot] = ColorFromPalette(RainbowColors_p, millis() / 8, 255, LINEARBLEND);
  FastLED.show();

  // when we reach 0, pause and take a note of the timestamp
  if (lead_dot == 0 && prev_dot != 0 && !paused) {
    paused = millis();
  }

  // when un-pausing, add the paused time to timebase to move the 0 to the present moment
  if (paused && millis() - paused >= 500) {
    timebase += millis() - paused;
    paused = 0;
  }
}