     }
   }
 }
+
+void advanceBit() {
+  if (++sequenceAtBit == 8) {
+    ++sequenceAt;
+    sequenceAtBit = 0;
+  }
+  if (sequenceAt == sequenceSize) {
+    inBinarySequence = false;
+  }
+}
+
+void binarySequenceLoop() {
+  if (Serial.available()) {
+    char ch = Serial.read();
+    switch (ch) {
+      case '1': {
+        sequence[sequenceAt] |= (1 << sequenceAtBit);
+        advanceBit();
+      } break;
+      case '0': {
+        sequence[sequenceAt] &= ~(1 << sequenceAtBit);
+        advanceBit();
+      } break;
+      case ';': {
+        Serial.print("Sending binary ");
+        Serial.print(sequenceAt * 8);
+        Serial.print("+");
+        Serial.print(sequenceAtBit);
+        Serial.println(" bits");
+        sendBinarySequence(sequence, sequenceAt * 8 + sequenceAtBit);
+        inBinarySequence = false;
+      } break;
+      default:
+        Serial.println("Aborting binary sequence");
+        inBinarySequence = false;
+    }
+  }
+}
+
+void loop() {
+  if (inBinarySequence) {
+    binarySequenceLoop();
+    if (!inBinarySequence) {
+      sequenceAt = 0;
+      prevSequenceSize = 0;
+    }
+  } else {
+    baseLoop();
+  }
+}


static unsigned long time = 0;

char initsequence[] = {
0,0,1,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,0,1,1,0,0,0,1,1,1,1,0,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,1,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,2,
0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,1,1,0,1,0,1,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,1,1,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,2,
0,0,1,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,2,

  digitalWrite(out, HIGH);
  digitalWrite(debug, HIGH);
  Serial.begin(9600);
  Serial.println("Start");
}

void sendSequence(const unsigned char* seq)
{
  Serial.println("Sending sequence");
  static unsigned long time = micros();
