#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 10 
#define BABY_LEDS 6

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 3
#define BUTTON_PIN A0
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];
int incomingByte = 0;
int state = 0;
int buttonState = 0;

void setup() { 
  Serial.begin(57600);
  Serial.println("resetting");
  LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
  LEDS.setBrightness(84);
}
 
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
  buttonState = analogRead(BUTTON_PIN);
  if (buttonState == 1024)
  {
    if (state == 0)
    {
      state = 1;
      Serial.println("state 1");
    }
  }
  else
  {
    state = 0;
    Serial.println("state 0");
  }
  static uint8_t hue = 0;
  if (state == 0)
  {
    // First slide the led in one direction
    for(int i = 0; i < NUM_LEDS; i++) {
      // Set the i'th led to red 
      leds[i] = CHSV(hue++, 255, 255);
      // Show the leds
      FastLED.show(); 
      // now that we've shown the leds, reset the i'th led to black
      // leds[i] = CRGB::Black;
      fadeall();
      // Wait a little bit before we loop around and do it again
      delay(100);
    }
    Serial.print("x");
  
    // Now go in the other direction.  
    for(int i = (NUM_LEDS)-1; i >= 0; i--) {
      // Set the i'th led to red 
      leds[i] = CHSV(hue++, 255, 255);
      // Show the leds
      FastLED.show();
      // now that we've shown the leds, reset the i'th led to black
      // leds[i] = CRGB::Black;
      fadeall();
      // Wait a little bit before we loop around and do it again
      delay(100);
    }
  }
  else
  {
    if(state == 1)
    {
      for(int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CHSV(0, 0, 0);
      }
      FastLED.show(); 
      delay(500);
    
      for(int i = 0; i < BABY_LEDS; i++) {
        leds[i] = CHSV(hue++, 255, 255);
        FastLED.show(); 
        delay(250);
      }
    
      state = 2;
    }
    else
    {
      for(int i = 0; i < BABY_LEDS; i++) {
        leds[i] = CHSV(hue++, 255, 255);        
      }
      delay(1000);
      FastLED.show(); 
      for(int i = 0; i < BABY_LEDS; i++) {
        leds[i] = CHSV((hue++)/2, 125, 125);        
      }
      delay(1000);
      FastLED.show(); 
    }
  }
}
