     else {  // pin_type == 'd'
 
         // CHECK INDEX BOUNDS
-        if (pin_index < 0 || pin_index >= NUM_DIGITAL_PINS) {
+        if (cmd_index < 0 || cmd_index >= NUM_DIGITAL_VALS) {
             Serial.print("Index out of range.\n");
             return;
         }
 
-        // READ PIN VALUE
-        pin_value = Serial.read();
-        if (pin_value < 0 || pin_value > 1) {
-            Serial.print("Pin value out of range.\n");
+        // READ CMD VALUE
+        cmd_value = Serial.read();
+        if (cmd_value < 0 || cmd_value > 1) {
+            Serial.print("cmd value out of range.\n");
             return;
         }
 
-        // WRITE TO PIN
-        if (pin_index == 0) {
-            digitalWrite(DIGITAL_PIN_0, pin_value);
-        }
-        else if (pin_index == 1) {
-            digitalWrite(DIGITAL_PIN_1, pin_value);
+        // COMPUTE
+        else {
+            compute();
         }
     }
-
-    //////////////////////////
-    //   SEND CONFIRMATION  //
-    //////////////////////////
-    //sprintf(buffer, "%u %u\n", pin_index, pin_value);
-    //Serial.print(buffer);
-
-    // delay(LOOP_DELAY);  // IS THIS NEEDED?
-}
-
-void processing() {
-    ;
-}
-
-void loop() {
-    txrx();
-    processing();
 }
 
 

    //////////////////////////
    //    ANALOG PIN        //
    //////////////////////////
    if (pin_type == 'a') {

        // CHECK INDEX BOUNDS
        if (pin_index < 0 || pin_index >= NUM_ANALOG_PINS) {
            Serial.print("Index out of range.\n");
            return;
        }

        // READ PIN VALUE
        pin_value = Serial.read();
        if (pin_value < 0 || pin_value > ANALOG_HI) {
            Serial.print("Pin value out of range.\n");
            return;
        }

        // WRITE TO PIN  (COULD USE ARRAY)
        if (pin_index == 0) {
            analogWrite(ANALOG_PIN_0, pin_value);
        }
        else if (pin_index == 1) {
            analogWrite(ANALOG_PIN_1, pin_value);
        }
    }


//            CONSTANTS             //
//////////////////////////////////////

#define ANALOG_HI     255

// SERIAL COM
#define SERIAL_DELAY 100  // MILLISECONDS
#define BAUD 9600
#define SERIAL_CONFIG SERIAL_8N1

#define NUM_DIGITAL_VALS 2
#define NUM_ANALOG_VALS 2

// *** PIERS: YOU MAY WANT TO CHANGE THESE *** //
#define ANALOG_PIN_0 10
#define ANALOG_PIN_1 9
#define DIGITAL_PIN_0 6
#define DIGITAL_PIN_1 5 



//////////////////////////////////////
//           VARIABLES              //
//////////////////////////////////////

// STORAGE FOR DATA READ FROM SERIAL COM
char cmd_type;
byte cmd_index;
byte cmd_value;

// STATE
byte digital_val_0;   // [0..1]
byte digital_val_1;   // [0..1]
byte analog_val_0;    // [0..255]
byte analog_val_1;    // [0..255]


//////////////////////////////////////
//           INTIIALIZE             //
//////////////////////////////////////

void setup() {
    // INTIALIZE SERIAL COM
    Serial.begin(BAUD);
    
    // *** PIERS: YOU MIGHT PUT INITIALIZATIN CODE HERE *** //
    // INITIALIZE COMPUTATION AND GPIO
    pinMode(ANALOG_PIN_0, OUTPUT);
    pinMode(ANALOG_PIN_1, OUTPUT);
    pinMode(DIGITAL_PIN_0, OUTPUT);
    pinMode(DIGITAL_PIN_1, OUTPUT);

    //Serial.println("botwurst_a ready...");
}


//////////////////////////////////////
//          COMPUTE                 //
//////////////////////////////////////

// *** PIERS: YOU MIGHT WANT TO PUT YOUR COMPUTATION HERE *** //
// *** THIS WILL GET CALLED EVERY TIME TIME A NEW COMMAND IS RECEIVED *** //
void compute() {

    // ANALOG
    if (cmd_type == 'a') {
        if (cmd_index == 0) {
            analogWrite(ANALOG_PIN_0, analog_val_0);
        }
        else if (cmd_index == 1) {
            analogWrite(ANALOG_PIN_1, analog_val_1);
        }
    }

    // DIGITAL
    else {  // cmd_type == 'd'
        if (cmd_index == 0) {
            digitalWrite(DIGITAL_PIN_0, digital_val_0);
        }
        else if (cmd_index == 1) {
            digitalWrite(DIGITAL_PIN_1, digital_val_1);
        }
    }
}


//////////////////////////////////////
//       MAIN LOOP / TXRX           //
//////////////////////////////////////

void loop() {

    //////////////////////////
    //     GET PIN TYPE     //
