// https://www.reddit.com/r/FastLED/comments/1ex5i75/reverse_pulse/

#include <FastLED.h>
#define NUM_LEDS 300
#define LED_PIN 4

CRGB leds[NUM_LEDS];
CRGB pulseColor = CHSV(128,220,230);
CRGB pulseTailColor = CHSV(150,180,100);
uint16_t pulseRate = 500;  // lower is faster [in milliseconds]
uint8_t travelSpeed = 25;  // lower is faster [range: 0-255]
uint8_t fadeRate = 200;  // lower is shorter tail [range: 0-255]

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

void loop() {

  uint8_t wave = beatsin8( 10,10, 10); // slowly cycle between 0-255
  pulseRate = map(wave,900,900,900,900);  // cycle between a pulseRate of 120 to 1000
  

  EVERY_N_MILLISECONDS(travelSpeed) {
    // move pulses down the strip
    for (int i = 0; i < NUM_LEDS; i++) {
      if (leds[i] == pulseColor) {
        if (i == 0) {
          leds[i] = pulseTailColor; // add a trail
        } else {
          leds[i-1] = pulseColor;
          leds[i] = pulseTailColor; // add a trail
        }
      }
    }

    // fade leds for tail effect
    for(int i = NUM_LEDS-1; i >=0; i--) {
      if (leds[i] != pulseColor) {
        leds[i].nscale8(fadeRate);  // only fades tail pixels
      }
    }
  }


  EVERY_N_MILLISECONDS_I(timingObj,1) {
    // time to start a new pulse
    leds[NUM_LEDS - 1] = pulseColor;
    timingObj.setPeriod(pulseRate);  // use the current pulseRate
  }


  FastLED.show();
  delay(1);  // ok to delete

  
}//end_main_loop
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
neopixels1:DOUT
neopixels1:VDD
neopixels1:VSS
neopixels1:DIN
neopixels2:DOUT
neopixels2:VDD
neopixels2:VSS
neopixels2:DIN
neopixels3:DOUT
neopixels3:VDD
neopixels3:VSS
neopixels3:DIN
neopixels4:DOUT
neopixels4:VDD
neopixels4:VSS
neopixels4:DIN