 // Pin connected to DS of 74HC595
 #define DATA_PIN 11
 
+// the serial port from which we read patterns
+#define COMPORT Serial
+
+// the speed of the serial port
+#define COMSPEED 9600
+
 // delay between patterns
 #define DELAY 150
 
-byte patterns[] = {
-  0x81,
-  0x42,
-  0x24,
-  0x18,
-  0x24,
-  0x42,
-  0xff,
-  0x00,
-  0xff,
-  0x00,
-  0xff,
-  0x00
-};
+// the patterns parsed from the serial port will be stored here
+// the pattern buffer size defines the maximum number of patterns
+// that may be sent in a serial command.
+#define PATTERN_BUFFER_SIZE 32
+byte patternBuffer[PATTERN_BUFFER_SIZE];
+byte patternCount;
+
+// the commands coming from the serial port will be stored here
+#define CMD_BUFFER_SIZE (PATTERN_BUFFER_SIZE*2)+1
+char  commandBuffer[CMD_BUFFER_SIZE+1];
+int   commandCursor = 0;
 
 void setup() {
   //set pins to output so you can control the shift register
   pinMode(LATCH_PIN, OUTPUT);
   pinMode(CLOCK_PIN, OUTPUT);
   pinMode(DATA_PIN, OUTPUT);
+  
+  // switch off the LEDs
+  writeToLeds(0);
+  
+  // start listening on the com port
+  COMPORT.begin(COMSPEED);
+  
 }
 
 void loop() {
+  // we always look for a new pattern before each iteration. this means that
+  // every pattern block will always be played to its end before a new one is
+  // read and displayed.
+  readPatternsFromSerial();
+  
   // count from 0 to 255 and display the number 
   // on the LEDs
-  for (int i = 0; i < sizeof(patterns); i++) {
-    // take the latchPin low so 
-    writeToLeds(patterns[i]);
+  for (int i = 0; i < patternCount; i++) {
+
+    writeToLeds(patternBuffer[i]);
     // pause before next value:
     delay(DELAY);
   }

    //take the latch pin high so the LEDs will light up:
    digitalWrite(LATCH_PIN, HIGH);
}

 This sketch reads commands from a serial line that define patterns which in turn are shifted
 out to an 74HC595 shift register connected to the Arduino. Think of it as one of those
 terribly annoying christmas flickerfucks, but you can control this one with bluetooth. :)
 
 The commands that come from serial are pretty simple: a row of hex encoded bytes. Those
 bytes are parsed and shifted out to the LEDs with 150ms delay between the different values.
 
 Try this one, it's quite pretty:
 010204081020408040201008040201008142241800ff00ff
 
 Program code by Gregor Ottmann, https://github.com/Zappes.
 Inspiration from the tutorial at http://arduino.cc/en/tutorial/ShiftOut
