 
 void setup() {
     Serial.begin(9600);
-    index1 = 0;
-    index2 = 0;
-    red = 0;
-    green = 0;
-    blue = 0;
-
     // Set the LED controller
     delay(1000);
     FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
     blackout();
-    if(DEBUG) { Serial.println("Lights engaged"); }
+    if(DEBUG) { 
+        Serial.println("Lights engaged"); 
+        loop_lights();
+    }
 
     // Set the status light
     pinMode(STATUS_PIN, OUTPUT);
-
 }
 
 void loop() {
+    // TODO: create a circular buffer to hold values + end value
+    /*
+    while(Serial.available() > 0) {
+        int val = Serial.read();
+        if(val == ESCPAPE) {
+            int ind1 = (currIndex + BUFFER_SIZE - 5) % BUFFER_SIZE;
+            int ind2 = (currIndex + BUFFER_SIZE - 4) % BUFFER_SIZE;
+            int r = (currIndex + BUFFER_SIZE - 3) % BUFFER_SIZE;
+            int g = (currIndex + BUFFER_SIZE - 2) % BUFFER_SIZE;
+            int b = (currIndex + BUFFER_SIZE - 1) % BUFFER_SIZE;
+            // combine index bytes
+            unsigned int index = ((unsigned int)serialBuffer[ind1] << 8) + 
+                                  (unsigned int)serialBuffer[ind2];
+            index = mapIndex(index);
+            // RGB, 0xFFAACC, 3 bytes
+            unsigned long hexcolor = ((unsigned long)serialBuffer[r] << 16) + 
+                                     ((unsigned long)serialBuffer[g] << 8) + 
+                                     (unsigned long)serialBuffer[b];
+            setColor(index, hexcolor);
+        } else {
+            serialBuffer[currIndex] = val;
+            currIndex = (currIndex + 1) % BUFFER_SIZE;
+        }
+    }
+    */
     // 2 bytes for the index, 3 for the color
     if ( Serial.available() >= 5 )  {
-        index1 = Serial.read();
-        index2 = Serial.read();
-        red = Serial.read();
-        green = Serial.read();
-        blue = Serial.read();
+        int index1 = Serial.read();
+        int index2 = Serial.read();
+        int red = Serial.read();
+        int green = Serial.read();
+        int blue = Serial.read();
 
         // combine index bytes
         unsigned int index = ((unsigned int)index1 << 8) + (unsigned int)index2;
+        index = mapIndex(index);
         // RGB, 0xFFAACC, 3 bytes
         unsigned long hexcolor = ((unsigned long)red << 16) + ((unsigned long)green << 8) + (unsigned long)blue;
 
         setColor(index, hexcolor);
     }
-
-    //FastLED.show();
 }
 
-

    }
}

void blackout() {
    for(int i = 0; i < NUM_LEDS; i++)
    { leds[i] = CRGB::Black; }

    FastLED.show();
    delay(2000);
}
void loop_lights() {
  // Move a single white led
    for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed++) {
        leds[whiteLed] = CRGB::White;
        // Show the leds (only one of which is set to white, from above)
        FastLED.show();

        delay(200);
        leds[whiteLed] = CRGB::Black;
    }

/***
Arduino controller script for a interactive, light up table.
Author: Bereket Abraham
***/
#include "FastSPI_LED2.h"

// col 13, row 8
#define NUM_LEDS 104
#define COL_SIZE 13
#define ROW_SIZE 8
#define DATA_PIN 6
#define STATUS_PIN 3
#define BUFFER_SIZE 5
#define DEBUG false

CRGB leds[NUM_LEDS];
int serialBuffer[] = {0,0,0,0,0};
int currIndex = 0;

void setColor(unsigned int index, unsigned long hexcolor) {
    // Accepts the LED index (int) and the 3 byte color # (unsigned long)
    leds[index] = hexcolor;
    FastLED.show();

