 }
 
 bool readByte(byte &receivedByte, int timeout) {
+  // Read a single byte from Serial, with a provided timeout
   long starttime = millis();
   while (!Serial.available())
     if ((millis() - starttime) > timeout)

void setup(void) {
  Wire.begin();
  setupDriver();
  for (byte output = 16; output-- > 0;)
    setDriverPinLevel(output, 0);
  Serial.begin(57600);
  Serial.println("[Lightbox]");
}

void loop(void) {
  static byte errorCount = 0;
  byte receivedByte;
  if (readByte(receivedByte, messageTimeout)) {
    errorCount = 0;
    switch (receivedByte) {
      case '\x01':
        messageAllOutputs();
        break;
      case '\x02':
        messageSingleOutput();
        break;
    }
  } else if (++errorCount > maxErrors) {
    // No transmission for 10 seconds, everything dark.
    for (byte output = 16; output-- > 0;)
      setDriverPinLevel(output, 0);
    errorCount = 0;
  }
}

void messageAllOutputs(void) {
  byte receivedByte, red, green, blue;
  if (readByte(receivedByte, characterTimeout) && receivedByte == '\x03')
    if (readByte(red, characterTimeout) &&
        readByte(green, characterTimeout) &&
        readByte(blue, characterTimeout))
      for (byte output = 5; output-- > 0;)
        setOutputColor(output, red, green, blue);
}

void messageSingleOutput(void) {
  byte receivedByte, red, green, blue, output;
  if (readByte(receivedByte, characterTimeout) && receivedByte == '\x04')
    if (readByte(output, characterTimeout) && output < 5 &&
        readByte(red, characterTimeout) &&
        readByte(green, characterTimeout) &&
        readByte(blue, characterTimeout))

}

void setOutputColor(byte output, byte red, byte green, byte blue) {
  // Set the given output to the configured red, green and blue levels.
  output *= 3;
  setDriverPinLevel(output++, red);
  setDriverPinLevel(output++, green);
