 #include <FastLED.h>
+#include <EEPROM.h>
+
+int eeprom_addr = 0;
 
 #define LED_PIN     5
 #define COLOR_ORDER GRB
 #define CHIPSET     WS2811
-#define BRIGHTNESS  200
+#define BRIGHTNESS  200 // DEFAULT
+
+#define PIN_BRIGHTNESS A0
+#define PIN_MODE 4
+#define PIN_LED A1
+
+int currentMode = 0;
+#define MAXMODE 4
+
+int buttonState;          
+int lastButtonState = LOW;
+unsigned long lastDebounceTime = 0;
+unsigned long debounceDelay = 75;
 
 const uint8_t kMatrixWidth = 20;
 const uint8_t kMatrixHeight = 10;
 const bool    kMatrixSerpentineLayout = false;
 
+bool isButtonPressed()
+{
+  int reading = digitalRead(PIN_MODE);
+  if (reading != lastButtonState) {
+    lastDebounceTime = millis();
+  }
+
+  if ((millis() - lastDebounceTime) > debounceDelay) {
+    if (reading != buttonState) {
+      buttonState = reading;      
+    }
+
+    lastButtonState = reading;
+
+    return buttonState == HIGH;
+  }
+
+  lastButtonState = reading;
+
+  return false;
+}
+
 uint16_t XY( uint8_t x, uint8_t y)
 {
   uint16_t i;
-  
-  if( kMatrixSerpentineLayout == false) {
+
+  if ( kMatrixSerpentineLayout == false) {
     i = (y * kMatrixWidth) + x;
   }
 
-  if( kMatrixSerpentineLayout == true) {
-    if( y & 0x01) {
+  if ( kMatrixSerpentineLayout == true) {
+    if ( y & 0x01) {
       // Odd rows run backwards
       uint8_t reverseX = (kMatrixWidth - 1) - x;
       i = (y * kMatrixWidth) + reverseX;


uint16_t XYsafe( uint8_t x, uint8_t y)
{
  if( x >= kMatrixWidth) return -1;
  if( y >= kMatrixHeight) return -1;
  return XY(x,y);
}

// Demo that USES "XY" follows code below

void loop()
{
//  FastLED.show();
//  FastLED.setBrightness(BRIGHTNESS);
}

void set_led_rgb(int x, int y, int r, int g, int b)

  set_led_rgb(0, 9, 14, 11, 8); set_led_rgb(1, 9, 14, 11, 9); set_led_rgb(2, 9, 14, 11, 9); set_led_rgb(3, 9, 13, 10, 7); set_led_rgb(4, 9, 13, 9, 6);  set_led_rgb(5, 9, 13, 11, 8); set_led_rgb(6, 9, 13, 12, 10);  set_led_rgb(7, 9, 13, 12, 10);  set_led_rgb(8, 9, 13, 12, 10);  set_led_rgb(9, 9, 13, 12, 10);  set_led_rgb(10, 9, 13, 12, 10); set_led_rgb(11, 9, 13, 12, 10); set_led_rgb(12, 9, 13, 12, 10); set_led_rgb(13, 9, 13, 11, 9);  set_led_rgb(14, 9, 13, 9, 6); set_led_rgb(15, 9, 14, 10, 7);  set_led_rgb(16, 9, 14, 11, 9);  set_led_rgb(17, 9, 14, 11, 9);  set_led_rgb(18, 9, 14, 11, 9);  set_led_rgb(19, 9, 14, 11, 9);
}

void setup() 
{
  pinMode(PIN_BRIGHTNESS, INPUT);
  pinMode(PIN_MODE, INPUT);
  pinMode(PIN_LED, OUTPUT);

  currentMode = EEPROM.read(eeprom_addr);
  
  // LEDColorCorrection { TypicalSMD5050 =0xFFB0F0, TypicalLEDStrip =0xFFB0F0, Typical8mmPixel =0xFFE08C, TypicalPixelString =0xFFE08C, UncorrectedColor =0xFFFFFF }
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(UncorrectedColor);
  FastLED.setBrightness( BRIGHTNESS );
}
