#include "FastLED.h"
#define NUM_LEDS 71 
CRGB leds[NUM_LEDS];
#define PIN 6

void setup()
{
  FastLED.addLeds<WS2813, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  Serial.begin(115200);
}

void loop()
{
  meteorRain( CRGB(255, 255, 255), 5, 100, 10 );
}

void meteorRain( CRGB color, uint8_t size, uint8_t decayAmount, uint8_t speed )  
{
  uint32_t now = millis();
  static uint32_t past = now;

  if ( now - past >= speed )
  {
    past = now;

    static int16_t pos = 0;
    static bool invertDirection = false;

    if ( invertDirection == false )
    {
      if ( pos >= size )
      {
        for ( int16_t i = 0; i <= pos - size; i++ )
        {
          decay( i, decayAmount );
        }
      }

      if ( pos < NUM_LEDS + size - 1 )
      {
        if ( pos < NUM_LEDS )
        {
          leds[pos] = color;

          for ( int16_t i = pos + 1; i < NUM_LEDS; i++ )
          {
            decay( i, decayAmount );
          }
        }
        pos++;
      }
      else
      {
        pos = NUM_LEDS - 1;
        invertDirection = true;
      }
    }

    else
    {
      if ( pos < NUM_LEDS - size )
      {
        for ( int16_t i = pos + size; i < NUM_LEDS; i++ )
        {
          decay( i, decayAmount );
        }
      }

      if ( pos > -size )
      {
        if ( pos >= 0 )
        {
          leds[pos] = color;

          for ( int16_t i = 0; i < pos; i++ )
          {
            decay( i, decayAmount );
          }
        }
        pos--;
      }
      else
      {
        static uint32_t past = 0;
        static uint32_t restart = 0;

        if ( past == 0 )
        {
          past = now;
          restart = random( 2000, 15000 );
          Serial.print( "Restarting in ");
          Serial.print( restart );
          Serial.println( " ms" );
        }

        if ( now - past >= restart )
        {
          past = 0;
          pos = 0;
          invertDirection = false;
        }
      }
    }

    FastLED.show();
  }
}

void decay( uint16_t id, uint8_t value )
{
  if ( 0 )
  {
    leds[id] = CRGB::Black;
  }
  else if ( random( 2 ) )
  {
    leds[id].fadeToBlackBy( value );
  }
}