// https://www.reddit.com/r/FastLED/comments/17h7che/resetting_a_sinbeat_function_to_zero_every_time/

#include <FastLED.h>

#define NUM_LEDS 28
CRGB leds[NUM_LEDS];

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

void loop() {
  static uint32_t timebase = 0;
  static bool active = false;

  if (! digitalRead(A0)) {
    // button pressed
    if (! active) {
      // the button has just this moment been pressed:
      // set timebase to current moment, for timeshifting beatsin16
      timebase = millis();
      active = true;
    } 
  } else {
    // button released; turn off beatsin16
    active = false;
  }

  if (active) {
    // add 0xc000 (three quarters of a cycle), to start sin16 from 0 each time
    uint16_t lead_dot = beatsin16(34, 0, NUM_LEDS - 1, timebase, 0xc000);
    leds[lead_dot] = ColorFromPalette(RainbowColors_p, millis() / 8, 255, LINEARBLEND);
  }
  fadeToBlackBy(leds, NUM_LEDS, 2);
  FastLED.show();

}