#include "FastLED.h"
//FIXED GLOBAL VARS
#define BRIGHTNESS 15
#define LED_TYPE NEOPIXEL  //define type of led
#define NUM_LEDS 256  //num of leds in strip
//#define DATA_PIN 11  //Define led data pin in
//#define Button 8
#define DATA_PIN 13  //for noiasca
#define Button A0
bool oldState = HIGH;
int showType = 0;
CRGB leds[NUM_LEDS];  // Initialize LED array
CRGBPalette16 currentPalette;
uint8_t hue = 0;
void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  pinMode(Button, INPUT_PULLUP);
  // put your setup code here, to run once:
  delay(2000); //for safe startup
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
}
void loop() {
  bool newState = digitalRead(Button);
  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(Button);
    if (newState == LOW) {
      showType++;
      if (showType > 8)
        showType = 0;
      Serial.print(F("new showType=")); Serial.println(showType);
      startShow(showType);
    }
  }
  // Set the last button state to the old state.
  oldState = newState;
  if (showType == 6) rainbowCycle(); // needs to be called permanentely
}
void fill(CRGB newColor)   // there might be an built function in FASTled also...
{
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = newColor;
  }
  FastLED.show();
}
void startShow(int g) {
  switch (g) {
    case 0: fill(CRGB::Black);
      break;
    case 1: fill(CRGB::Red);
      break;
    case 2: fill(CRGB::Green);
      break;
    case 3: fill(CRGB::Yellow);
      break;
    case 4: fill(CRGB::Blue);
      break;
    case 5: fill(CRGB::Purple);
      break;
    case 6:
      // leds[i] = CHSV(hue + (i * 200), 255, 255);
      rainbowCycle();
      break;
    case 7: fill(CRGB::Aqua);
      break;
    case 8: fill(CRGB::HotPink);
      break;
  }
}
void rainbowCycle() {
  for (int i = 0; i < NUM_LEDS; ++i) {
    leds[i] = CHSV(hue + (i * 10), 255, 255);
  }
  EVERY_N_MILLISECONDS(15) {
    hue++;
  }
  FastLED.show();
}