 RGBdriver Driver(CLK,DIO);
 static int BAUDRATE = 9600;
 int red,green,blue;
-int* rbg[3] = {&red, &green, &blue};
-// probably actually learn about pointers before using this, but it'd make some things simpler.
+int* rgb[3] = {&red, &green, &blue};
+// In use, & means "address of"; * means "follow this address".
+// This is an array of pointers (which lead to our RGB vars).  Write
+// to it with *rgb[x], which means "follow the address at rgb[x]" which
+// leads to a color variable.
 
 void setup() {
+  if (SINGLE_LED) { // CC on pin 7
+    pinMode(7,OUTPUT);
+    pinMode(6,OUTPUT);
+    pinMode(5,OUTPUT);
+    pinMode(4,OUTPUT);
+  }
   Serial.begin(BAUDRATE);
-
 }
 
 
 int timeOutCount = 0;
+char input[128];
 
 void loop() {
 
-
-  char input[255];
-
+  
   Serial.readStringUntil('\n').toCharArray(input,255);
-  if (input!="") { // if connected
+  if (input!="") { // if connected    
     switch (input[0]) {
+      case '?': {
+        Serial.println(red);
+        Serial.println(green);
+        Serial.println(blue);
+        break;
+      }
+      case 'X' : {
+        red=0; green=0; blue=0;
+        setOutput(*rgb);
+        break;
+      }
+      case '!': {
+        red=0; green=0; blue=0;
+        setOutput(red,green,blue);
+        break;
+      }
       case 'V': { // set value specified in V#FFFFFF input
-        // function strtol() returns a long when given (string,end pointer,radix)
-        long long number = strtol( &input[2], NULL, 16);   // from Stack Exchange
-        // Split them up into r, g, b values
-        int red = number >> 16;
-        int green = number >> 8 & 0xFF;
-        int blue = number & 0xFF;                           // end SE code=
-        setOutput(red,green,blue);
-        
-        // report back hex values
-        // to-do: fix this to include leading zeroes; right now 0F0F0F is transmitted as FFF
+        char colorInput[] = {input[1],input[2],input[3],input[4],input[5],input[6],input[7],'\0'}; // who needs loops
+        if (DEBUGGING_MODE) { Serial.print("Serial input:"); Serial.println(colorInput); }
+        decodeHex(colorInput,*rgb);
+        setOutput(*rgb);
+
+        // echo current colors:
+        Serial.print('#');
+        if (red<=16) {Serial.print('0');}
         Serial.print(red, HEX);
+        if (green<=16) {Serial.print('0');}
         Serial.print(green, HEX);
+        if (blue<=16) {Serial.print('0');}
         Serial.println(blue, HEX);
 
-        if (DEBUG) {
+        if (DEBUGGING_MODE) {
         Serial.print("red: ");
         Serial.println(red, DEC);
         Serial.print("green: ");

  }
}

  void setOutput( int red, int green, int blue) {
    //"local variable hides a field" :p
    Driver.begin();
    Driver.SetColor(red, green, blue);
    Driver.end();
  }

  void setOutput( int color[]) {
    if (sizeof(color)!=3) {
      // log error message
    } else {
      setOutput(color[0],color[1],color[2]);
    }
  }

// TODO: reuse relevant driver code (like two lines)
//  while (Serial.available() > 0) {
//    // each input is in the form 000,123,255\n
//    
//    //parseInt skips the first non-digit and non-minus sign chars, so input is split:
//    red = Serial.parseInt();  // 123
//    green = Serial.parseInt();// (,)123
//    blue = Serial.parseInt(); // (,)123
//    if (Serial.read() == '\n') { //data probably received successfuly
//      red = constrain(red, 0, 255);
//      green = constrain(green, 0, 255);
//      blue = constrain(blue, 0, 255);
//
//      Driver.begin();
//      Driver.SetColor(red, green, blue);
//      Driver.end();
//
//      // report back hex values
//      Serial.print(red, HEX);
//      Serial.print(green, HEX);
//      Serial.println(blue, HEX);
//
//      
//     }
//  }
//}

        Serial.println(blue, DEC);
        Serial.println("");
        }
        
        break;
      }
    case 'G' : {
        // run gradient pulse between a and b with appropriate timestep; "G#000000:#123456:time" input
        if (input[9]=='#') {
          char hex1[7], hex2[7];
          char timev[7]; //well our buffer is 7 chars now.
          for (int x=0; x<7; x++) {
            hex1[x]=input[x+1];
            hex2[x]=input[x+9];
            timev[x]=input[x+16];
          }
          int col1[4],col2[4];
          decodeHex(hex1,col1);
          decodeHex(hex2,col2);

          float timeVal = atoi(timev); //use strtol or sscanf instead

          gradientPulse(col1,col2,timeVal);

          if (DEBUGGING_MODE) {
            Serial.println(hex1);
            Serial.println(hex2);
            Serial.println(timev);
          }
        } else {
          Serial.println("Error: malformed gradient request");
          Serial.println(input);
        }
        break;
      }
    }
