 int BLUPIN = 4;
 
 // Defaults
-String TYPE = "blink";   // blink, pulse
-int LOOP = 3;            // 3, 2, 1
-int TIME = 100;          // 500, 250, 100, 50 (milliseconds)
-int REPT = 15000;        // 30000, 15000, 5000, 3000, -1 (milliseconds)
-int RED = 255;           // 0-255
-int GRE = 255;           // 0-255
-int BLU = 255;           // 0-255
-
-boolean REPEATING = false;
+int TYPE = 0;
+int NUMB = 0;
+int TIME = 0;
+int REPT = 0;
+int arrayNUMB[] = {1, 2, 3, 5};
+int arrayTIME[] = {50, 100, 250, 500};
+int arrayREPT[] = {0, 5000, 15000, 30000};
+
+unsigned char API;
+unsigned char R;
+unsigned char G;
+unsigned char B;
 
 void setup()
 {
-   pinMode(BUT, INPUT); 
-   pinMode(REDPIN, OUTPUT);
-   pinMode(GREPIN, OUTPUT);
-   pinMode(BLUPIN, OUTPUT);
-
-   // AC-BT v4 defaults to 9600.
-   btSerial.begin(9600);
-   //btSerial.write("AT+RENEW"); // Reset all settings.
-   delay(250);
-   btSerial.write("AT+ROLE0"); // Slave mode (0: Peripheral, 1: Central, default: 0)
-   delay(250);
-   btSerial.write("AT+MODE2"); // (0: Tranmission, 1: PIO+0, 2: Remote Control+0, default: 0)
-   delay(250);
-   btSerial.write("AT+IMME1"); // (0: work immediately, 1: wait for AT+ commands, wait for AT+START to resume work, default: 0) Don't enter transmission mode until told. ("AT+IMME0" is wait until "AT+START" to work. "AT+WORK1" is connect right away.)
-   delay(250);
-   btSerial.write("AT+BAUD0");
-   delay(250);
-   btSerial.write("AT+NAMETurquoiseB");
-   delay(250);
-   btSerial.write("AT+PASS123456");
-   delay(250);
-   btSerial.write("AT+START"); // Work immediately when AT+IMME1 is set.
-   
-   TIME_START = millis();
+  pinMode(BUTT, INPUT); 
+  pinMode(REDPIN, OUTPUT);
+  pinMode(GREPIN, OUTPUT);
+  pinMode(BLUPIN, OUTPUT);
+  
+  // AC-BT v4 defaults to 9600.
+  btSerial.begin(9600);
+  //btSerial.write("AT+RENEW"); // Reset all settings.
+  delay(250);
+  btSerial.write("AT+ROLE0"); // Slave mode (0: Peripheral, 1: Central, default: 0)
+  delay(250);
+  btSerial.write("AT+MODE2"); // (0: Tranmission, 1: PIO+0, 2: Remote Control+0, default: 0)
+  delay(250);
+  btSerial.write("AT+IMME1"); // (0: work immediately, 1: wait for AT+ commands, wait for AT+START to resume work, default: 0) Don't enter transmission mode until told. ("AT+IMME0" is wait until "AT+START" to work. "AT+WORK1" is connect right away.)
+  delay(250);
+  btSerial.write("AT+BAUD0");
+  delay(250);
+  btSerial.write("AT+NAMETurquoiseB");
+  delay(250);
+  btSerial.write("AT+PASS123456");
+  delay(250);
+  btSerial.write("AT+START"); // Work immediately when AT+IMME1 is set.
+  delay(250);
+  
+  TIME_START = millis();
 }
 
 void loop()
 {
   // clear button
-  BUTT_STATE = digitalRead(BUT);
+  BUTT_STATE = digitalRead(BUTT);
   if(BUTT_STATE == HIGH) {
-    REPEATING = false;
   }
   // read from bluetooth
+  int index = 0;
   if(btSerial.available()) {
-    digitalWrite(BLUPIN, HIGH);
     while(btSerial.available()) {
-      BUFFER += (char)btSerial.read();
-      delay(1);
-    }
-    
-    String buff = "";
-    int index = 0;
-    for(int i=0; i<BUFFER.length(); i++) {
-      // copy buffer
-      buff += BUFFER[i];
-      
-      // clear buffer
-      if(BUFFER[i] == ':') {
-        buff = "";
-      }
-      
-      // get a value
-      if(BUFFER[i+1] == ':') {
-        if(index == 0) {
-          TYPE = buff;
-          index++;
-        }
-        else if(index == 1) {
-          LOOP = buff.toInt();
-          index++;
-        }
-        else if(index == 2) {
-          TIME = buff.toInt();
-          index++;
-        }
-        else if(index == 3) {
-          REPT = buff.toInt();
-          if(REPT > 0)
-          {
-            REPEATING = true;
-          }
-          else if(REPT == -1) {
-            REPEATING = false;
-          }
-          index++;
-        }
-        else if(index == 4) {
-          RED = HEXToRGB(buff[0], buff[1]);
-          GRE = HEXToRGB(buff[2], buff[3]);
-          BLU = HEXToRGB(buff[4], buff[5]);
-          index++;
-        }
-        buff = "";
-      }
-    }
-    // clear buffer
-    BUFFER = "";
-    
-    if(TYPE == "blink") {
-      blinkRGB(LOOP, TIME, RED, GRE, BLU);
-    }
-    else if(TYPE == "pulse") {
-      pulseRGB(LOOP, TIME, RED, GRE, BLU);
-    }
-    else if(TYPE == "clear") {
-      REPEATING = false;
-    }
-    else {
-      blinkRGB(LOOP, TIME, RED, GRE, BLU);
+      API = btSerial.read();
+      delay(1);
+      R = btSerial.read();
+      delay(1);
+      G = btSerial.read();
+      delay(1);
+      B = btSerial.read();
+      delay(1);
+    }
+    
+    // parse API
+    REPT = 0;
+    TIME = 0;
+    NUMB = 0;
+    TYPE = 0;
+    
+    REPT = API & 3;
+    API >>= 2;
+    TIME = API & 3;
+    API >>= 2;
+    NUMB = API & 3;
+    API >>= 2;
+    TYPE = API &3;
+    
+    // blink
+    if(TYPE == 0) {
+      blinkRGB(arrayNUMB[NUMB], arrayTIME[TIME]);
+    }
+    // pulse
+    else if(TYPE == 1) {
+      pulseRGB(arrayNUMB[NUMB], arrayTIME[TIME]);
+    }
+    // turn on
+    else if(TYPE == 2) {
+      onRGB();
+    }
+    // turn off
+    else if(TYPE == 3) {
+      offRGB();
     }
   }
   
   // repeat
-  int time_end = millis();
-  int time_diff = time_end - TIME_START;
-  if(time_diff > REPT) {
-    TIME_START = millis();
-    if(REPEATING) {
-      blinkRGB(LOOP, TIME, RED, GRE, BLU);
+  if(REPT > 0) {
+    int time_end = millis();
+    int time_diff = time_end - TIME_START;
+    
+    if(time_diff > arrayREPT[REPT]) {
+      TIME_START = millis();
+      if(TYPE == 0) {
+      blinkRGB(arrayNUMB[NUMB], arrayTIME[TIME]);
+      }
+      // pulse
+      else if(TYPE == 1) {
+        pulseRGB(arrayNUMB[NUMB], arrayTIME[TIME]);
+      }
     }
   }
 }
 
 // blinkRGB - blinks an RGB LED
 // params:
-//   looper: int - amount of times blink the LED
-//   time: int - time for the delay between on/off
-//   red: int - red 
-//   gre: int - green
-//   blu: int - blue
-void blinkRGB(int looper, int time, int red, int gre, int blu) {
-  for(int i=0; i<looper; i++) {
-    analogWrite(REDPIN, red);
-    analogWrite(GREPIN, gre);
-    analogWrite(BLUPIN, blu);
+//  numb: int - number of blinks
+//  time: int - delay between each blink (millis)
+void blinkRGB(int numb, int time) {
+  for(int i=0; i<numb; i++) {
+    analogWrite(REDPIN, R);
+    analogWrite(GREPIN, G);
+    analogWrite(BLUPIN, B);
     delay(time);
     analogWrite(REDPIN, 0);
     analogWrite(GREPIN, 0);

  else if(time == 50) {
    DELAY = 1;
  }
  for(int i=0; i<looper; i++) {
    for(int j=0; j<255; j++) {
      if(j <= red) {
        analogWrite(REDPIN, j);
      }
      if(j <= gre) {
        analogWrite(GREPIN, j);
      }
      if(j <= blu) {
        analogWrite(BLUPIN, j);
      }
      delay(DELAY);
    }
    for(int k=255; k>=0; k--) {
      if(k <= red) {
        analogWrite(REDPIN, k);
      }
      if(k <= gre) {
        analogWrite(GREPIN, k);
      }
      if(k <= blu) {
        analogWrite(BLUPIN, k);
      }
      delay(DELAY);
    }
  }
}

int HEXToRGB(char first, char second) {
  int f = CharToHEX(first);
  int s = CharToHEX(second);
  return (f*16)+s;
}

int CharToHEX(char x) {
  int y = 0;
  if(x == '1') y = 1;
  else if(x == '2') y = 2;
  else if(x == '3') y = 3;
  else if(x == '4') y = 4;
  else if(x == '5') y = 5;
  else if(x == '6') y = 6;
  else if(x == '7') y = 7;
  else if(x == '8') y = 8;
  else if(x == '9') y = 9;
  else if(x == 'a') y = 10;
  else if(x == 'b') y = 11;
  else if(x == 'c') y = 12;
  else if(x == 'd') y = 13;
  else if(x == 'e') y = 14;
  else if(x == 'f') y = 15;
  return y;
}

  }
}

// pulse - pulses an RGB LED
// params:
//   looper: int - number of pulses
//   time: int - delay between each pulse (millis)
void pulseRGB(int numb, int time) {
  int DELAY = 1;
  if(time == 500) {
    DELAY = 8;
