#include <FastLED.h> // http://fastled.io/docs/files.html

#define NUMPIX 8
#define PIXPIN 4
#define MAXBRIGHT 255 // pixel brightness, 0 - 255
CRGB pixel[NUMPIX]; // create object to control [pixel]

unsigned long fadeTimer, fadeTimeout = 250;
int wait = 1000; // delay time

void setup() {
  Serial.begin(115200); // for debug
  randomSeed(analogRead(A0));

  FastLED.addLeds<WS2812B, PIXPIN, GRB>(pixel, NUMPIX);
  FastLED.setBrightness(MAXBRIGHT);
  FastLED.clear(); // empty pixel buffer
  FastLED.show(); // display empty buffer
}

void loop() {
  // walkingRGB(); // slow moving, each LED in each WS2812
  // walkingwhite(); // slow moving white
  // cylon(); // one pixel moving
  // primarycolors(); // random primary (RGBW) and secondary (CYMK) colors
  inbetweencolors(); // left three pixels are "inbetween colors", right three pixels are counting
}

void walkingwhite() {
  Serial.print("Walking White: ");
  for (int i = 0; i < NUMPIX; i++) {
    pixel[i] = CRGB(255, 255, 255);
    FastLED.show();
    Serial.print(i);
    Serial.print(" ");
    delay(wait);
    FastLED.clear();
  }
  Serial.println();
  FastLED.show();
}

void walkingRGB() {
  Serial.print("Walking RGB:");
  for (int i = 0; i < NUMPIX; i++) {
    Serial.print(" ");
    Serial.print(i);
    for (int j = 0; j < 3; j++) {
      switch (j) {
        case 0: Serial.print("R"); break;
        case 1: Serial.print("G"); break;
        case 2: Serial.print("B"); break;
      }
      pixel[i] = CRGB(255 * (j == 0), 255 * (j == 1), 255 * (j == 2));
      FastLED.show();
      delay(wait / 3);
    }
    FastLED.clear();
    FastLED.show();
  }
  Serial.println();
}

void cylon() {
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < NUMPIX; i++) {
      if (!j)
        pixel[i] = CRGB(255, 255, 255); // white
      else
        pixel[NUMPIX - 1 - i] = CRGB(255, 255, 255);
      FastLED.show();
      FastLED.clear();
      delay(100);
    }
  }
}

void primarycolors() {
  int r = random(2); int g = random(2); int b = random(2); int p = random(8);
  pixel[p] = CRGB(255 * r, 255 * g, 255 * b);
  FastLED.show();
  delay(50);
}


void inbetweencolors() {
  int wait = 250;
  pixel[0] = CRGB(  0, 127, 255); // cyn
  pixel[1] = CRGB(  0, 255, 255); // cyn
  pixel[2] = CRGB(  0, 255, 127); // cyn
  pixel[7] = CRGB(  0,   0,   0); // blk
  pixel[5] = CRGB(127, 127, 127); // wht
  FastLED.show();
  delay(wait);
  pixel[0] = CRGB(127, 255,   0); // yel
  pixel[1] = CRGB(255, 255,   0); // yel
  pixel[2] = CRGB(255, 127,   0); // yel
  pixel[5] = CRGB(  0,   0,   0); // blk
  pixel[6] = CRGB(127, 127, 127); // wht
  FastLED.show();
  delay(wait);
  pixel[0] = CRGB(127,   0, 255); // mag
  pixel[1] = CRGB(255,   0, 255); // mag
  pixel[2] = CRGB(255,   0, 127); // mag
  pixel[6] = CRGB(  0,   0,   0); // blk
  pixel[7] = CRGB(127, 127, 127); // wht
  FastLED.show();
  delay(wait);
}

// pixel(1=CRGB(255,   0,   0); // red
// pixel(5=CRGB(255, 255,   0); // yel
// pixel(2=CRGB(  0, 255,   0); // grn
// pixel(4=CRGB(  0, 255, 255); // cyn
// pixel(3=CRGB(  0,   0, 255); // blu
// pixel(6=CRGB(255,   0, 255); // mag

// pixel(0=CRGB(255, 255, 255); // wht
// pixel(7=CRGB(  0,   0,   0); // blk
1000uF