#include "FastLED.h"
#include <Adafruit_NeoPixel.h>

#define NUM_LEDS 20
CRGB leds[NUM_LEDS];

#define LED_TYPE WS2812
#define PIN 23
#define COLOR_ORDER GRB
#define BRIGHTNESS 255

void setup()
{
  Serial.begin(9600); 
  FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness( BRIGHTNESS );
}

void loop() {
  byte red,blue,green;

  for (int i = 0; i <= 3; i++) {
    switch (i) {
      case 0:
        Serial.println("Color is white");
        red = 0xff; blue = 0xff; green = 0xff;  // color is white
        break;
      case 1:
        Serial.println("Color is red");
        red = 0xff; blue = 0x0; green = 0x0;  // color is red
        break;
      case 2:
        Serial.println("Color is blue");
        red = 0x0; blue = 0xff; green = 0x0;  // color is blue
        break;
      case 3:
        Serial.println("Color is green");
        red = 0x0; blue = 0x0; green = 0xff;  // color is green
        break;
      default:
        Serial.println("Error - unexpected value  of i");
        break;
    }

    for (int j = 0; j <= 20; j++) {
      Sparkle(red, blue, green, 200);
    }

  }
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);

  Serial.print("Pixel value is ");
  Serial.println(Pixel);

  setPixel(Pixel,red,green,blue);
  showStrip();

  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}