#include "FastLED.h"

#define LED_DATA_A 6
#define LED_DATA_B 7
#define LED_DATA_C 8

#define COLOR_ORDER BGR
#define LED_TYPE NEOPIXEL

#define NUM_LEDS 40 // the tail should disappear off the strip, the real strips have 72 LEDs

CRGB ledsA[NUM_LEDS];
CRGB ledsB[NUM_LEDS];
CRGB ledsC[NUM_LEDS];

bool stripA = true;
bool stripB = true;
bool stripC = true;

const byte huesUA[] = {62, 144};
byte hueA = 62;
byte hueB = 62;
byte hueC = 62;

byte ledPosA = 0;
byte ledPosB = 0;
byte ledPosC = 0;

byte fadeA = 16;
byte fadeB = 16;
byte fadeC = 16;
byte fadeShort = 80;
byte fadeLong = 16;

int intervalShort = 700;
int intervalLong = 3800;

void setup() {
  FastLED.addLeds<LED_TYPE, LED_DATA_A>(ledsA, NUM_LEDS);
  FastLED.addLeds<LED_TYPE, LED_DATA_B>(ledsB, NUM_LEDS);
  FastLED.addLeds<LED_TYPE, LED_DATA_C>(ledsC, NUM_LEDS);

  FastLED.setTemperature(Tungsten100W);

  randomSeed(analogRead(1)); // 0 used by potentiometer
}

void loop()
{
  EVERY_N_MILLISECONDS_I(timerA, intervalShort)
  {
    timerA.setPeriod( random(intervalShort, intervalLong));
    stripA = true;
    fadeA = random(fadeLong, fadeShort);
  }

  EVERY_N_MILLISECONDS_I(timerB, intervalShort)
  {
    timerB.setPeriod( random(intervalShort, intervalLong));
    stripB = true;
    fadeB = random(fadeLong, fadeShort);
  }

  EVERY_N_MILLISECONDS_I(timerC, intervalShort)
  {
    timerC.setPeriod( random(intervalShort, intervalLong));
    stripC = true;
    fadeC = random(fadeLong, fadeShort);
  }

  if (stripA)
  {
    EVERY_N_MILLISECONDS(50)
    {
      ledsA[ledPosA] = CHSV(hueA, 192, 224);

      ledPosA++;

      if (ledPosA == NUM_LEDS)
      {
        hueA = huesUA[random(0, 2)];

        ledPosA = 0;

        stripA = false;
      }

      fadeToBlackBy(ledsA, NUM_LEDS, fadeA);
    }
  }

  if (stripB)
  {
    EVERY_N_MILLISECONDS(50)
    {
      ledsB[ledPosB] = CHSV(hueB, 192, 224);

      ledPosB++;

      if (ledPosB == NUM_LEDS)
      {
        hueB = huesUA[random(0, 2)];

        ledPosB = 0;

        stripB = false;
      }

      fadeToBlackBy(ledsB, NUM_LEDS, fadeB);
    }
  }

  if (stripC)
  {
    EVERY_N_MILLISECONDS(50)
    {
      ledsC[ledPosC] = CHSV(hueC, 192, 224);

      ledPosC++;

      if (ledPosC == NUM_LEDS)
      {
        hueC = huesUA[random(0, 2)];

        ledPosC = 0;

        stripC = false;
      }

      fadeToBlackBy(ledsC, NUM_LEDS, fadeC);
    }
  }

  FastLED.show();
}