#include "FastLED.h"

#define NUM_LEDS 19
#define DATA_PIN 4

CRGB leds[NUM_LEDS];

const int pinEncoder1 = 2;
const int pinEncoder2 = 3; 
const int MenuCount = 16;
int MenuIndex = 0;

void setup() {
  pinMode(pinEncoder1,INPUT_PULLUP);
  pinMode(pinEncoder2,INPUT_PULLUP);
  LEDS.addLeds<WS2812B,DATA_PIN,GRB>(leds,NUM_LEDS);
  LEDS.setBrightness(100);
  attachInterrupt(digitalPinToInterrupt(2),EnISR , FALLING);

}

void EnISR ()
{
  while(!digitalRead(pinEncoder1));
    if(digitalRead(pinEncoder2)==HIGH){
      MenuIndex++;
      if(MenuIndex >= MenuCount) MenuIndex = 0;
    } else {
      MenuIndex--;
      if(MenuIndex < 0) MenuIndex = MenuCount - 1;
    }
 
}


void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() {
displayMenu();
}


void displayMenu()
{static unsigned long curtime = millis();
switch(MenuIndex)
{
  case 1:fill_solid(leds, NUM_LEDS, CRGB::Red);
  FastLED.show();
  break;

  case 2:fill_solid( leds, NUM_LEDS, CRGB::Green);
  FastLED.show();
  break;
  
  case 3: fill_solid( leds, NUM_LEDS, CRGB::Blue);
  FastLED.show();
  break;

  case 4: fill_solid( leds, NUM_LEDS, CRGB::Yellow);
  FastLED.show();
  break;

  case 5: fill_solid( leds, NUM_LEDS, CRGB::Pink);
  FastLED.show();
  break;
  
  case 6: slowwipe(127,255,212);
  break;

  case 7: slowwipe(220,20,60);
  break;
  
  case 8: slowwipe(173,255,47);
  break;

  case 9:runner(128,0,128);
  break; 
  
  case 10: runner(255,20,147);
  break; 

  case 11: runner(65,105,225);
  break; 

  case 12: blin(173,255,47);
  break;

  case 13: blin(255,105,180);
  break;

  case 14: blin(0,191,255);
  break;

  case 15: blin(255,69,0);
  break;
 
  default : 
  FastLED.clear();
  FastLED.show();
  break;
    
}
  curtime = millis();
}


void slowwipe(int r, int g, int b)
{
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB(r,g,b);
    FastLED.show(); 
    fadeall();
    delay(50);
  }

for(int i = (NUM_LEDS)-1; i >= 0; i--) {
    leds[i] = CRGB(r, g, b);
    FastLED.show();
    fadeall();
    delay(50);
  }
}

void runner(int r, int g, int b)
{
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB(r, g, b);
    FastLED.show(); 
    leds[i] = CRGB::Black;
    fadeall();
    delay(10);
  }

for(int i = (NUM_LEDS)-1; i >= 0; i--) {
    leds[i] = CRGB(r, g, b);
    FastLED.show();
    leds[i] = CRGB::Black;
    fadeall();
    delay(10);
  }
  
}


void blin(int r, int g, int b)
{
  fill_solid( leds, NUM_LEDS, CRGB(r,g,b));
   FastLED.show(); 
    delay(100);
   fill_solid( leds, NUM_LEDS, CRGB::Black);
   FastLED.show(); 
     delay(100);
  
}


