   Serial.println("Done sending sequence");
 }
 
+void sendBinarySequence(const unsigned char* seq, int numBits)
+{
+  static unsigned long time = micros();
+  int curBit = 0;
+  int curByte = 0;
+  for (int c = 0; c < numBits; ++c) {
+    int value = ((seq[curByte] >> curBit) & 1) ? HIGH : LOW;
+    digitalWrite(out, value);
+    digitalWrite(debug, value);
+    time += 52;
+    if (++curBit == 8) {
+      curBit = 0;
+      ++curByte;
+    }
+    unsigned int delta = time - micros();
+    delayMicroseconds(delta);
+  }
+  digitalWrite(out, HIGH);
+  digitalWrite(debug, HIGH);
+  
+
+  curBit = 0;
+  curByte = 0;
+  Serial.print("Sent ");
+  for (int c = 0; c < numBits; ++c) {
+    int value = ((seq[curByte] >> curBit) & 1);
+    Serial.print(value ? '1' : '0');
+    if (++curBit == 8) {
+      curBit = 0;
+      ++curByte;
+    }
+  }
+  Serial.println();
+
+}
+
 void doit() {
   sendSequence(initsequence);
 }
 
-const unsigned sequenceSize = 100;
-char sequence[sequenceSize + 1];
+const unsigned sequenceSize = 200;
+unsigned char sequence[sequenceSize + 1];
 int sequenceAt = 0;
 int prevSequenceSize = 0;
 
-void loop() {
+int sequenceAtBit = 0;
+int inBinarySequence = 0;
+
+void baseLoop() {
   if (Serial.available()) {
     char ch = Serial.read();
     switch (ch) {

      case '0': {
        if (sequenceAt < sequenceSize) {
          sequence[sequenceAt++] = 0;
        }
      } break;
      case '1': {
        if (sequenceAt < sequenceSize) {
          sequence[sequenceAt++] = 1;
        }
      } break;
      case ';': {
        if (!prevSequenceSize || sequenceAt > 0) {

  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();
