#include <FastLED.h>
#include <IRremote.h>

#define RECV_PIN            2       // Signal Pin of IR receiver
#define DATA_PIN            3       // Set your datapin
#define NUM_LEDS            256     // Number Splendida LEDs
#define LED_TYPE            WS2812B // LEDs type
#define COLOR_ORDER         GRB     // Color order of leds
#define BRIGHTNESS          255     // LED brightness
#define MAX_POWER_MILLIAMPS 800     // Default i set 800 mA for safety

// IR NEC command
#define RECV_KB0 104
#define RECV_KB1 48
#define RECV_KB2 24
#define RECV_KB3 122
#define RECV_KB4 16
#define RECV_KB5 56
#define RECV_KB6 90
#define RECV_KB7 66
#define RECV_KB8 74
#define RECV_KB9 82

uint8_t gCurrentPatternNumber = 0;  // Index number of which pattern is current
uint8_t gLastPatternNumber = 0;     // Last index number of the current pattern

CRGB leds[NUM_LEDS];

IRrecv irrecv(RECV_PIN);

typedef void (*SimplePatternList[])();
SimplePatternList gPatterns =      // List of patterns
{

};

void setup() {
  Serial.begin(9600);
  Serial.print("Current Pattern: ");
  Serial.println(gCurrentPatternNumber);
  delay(1000);

  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip );
  // FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_POWER_MILLIAMPS);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear();

  irrecv.enableIRIn();              // Start the receiver
}

void loop() {
  EVERY_N_MILLIS(10) // Speed of change patterns periodically
  {
    if (irrecv.decode()) {

      // Get control code
      switch (irrecv.decodedIRData.command) {
        case RECV_KB1: gCurrentPatternNumber = 1;
          break;
        case RECV_KB2: gCurrentPatternNumber = 2;
          break;
        case RECV_KB3: gCurrentPatternNumber = 3;
          break;
        case RECV_KB4: gCurrentPatternNumber = 4;
          break;
        case RECV_KB5: gCurrentPatternNumber = 5;
          break;
        case RECV_KB6: gCurrentPatternNumber = 6;
          break;
        case RECV_KB7: gCurrentPatternNumber = 7;
          break;
        case RECV_KB8: gCurrentPatternNumber = 8;
          break;
        case RECV_KB9: gCurrentPatternNumber = 9;
          break;
        case RECV_KB0: gCurrentPatternNumber = 0;
          break;
      }

      if (gLastPatternNumber != gCurrentPatternNumber) {
        gLastPatternNumber = gCurrentPatternNumber;
        Serial.print("Current Pattern: ");
        Serial.println(gCurrentPatternNumber);
      }

      irrecv.resume();
    }
  }

  EVERY_N_SECONDS(1) // Speed of change patterns periodically
  {

  }

  // gPatterns[gCurrentPatternNumber]();
  // FastLED.show();
}