     }
   }
   Serial.println();
-
+}
+
+// sends stuff from sequence, sequenceAtBit/sequenceAtByte
+void sendBinarySequenceHw()
+{
+  noInterrupts();
+  writeBitsLeft = sequenceAt * 8 + sequenceAtBit;
+  writeCurBit = 0;
+  writeCurByte = 0;
+  interrupts();
+  
+  while (writeBitsLeft > 0) {
+    // wait for writing to go through
+  }
+  Serial.println(".");
 }
 
 void doit() {
   sendSequence(initsequence);
 }
-
-const unsigned sequenceSize = 200;
-unsigned char sequence[sequenceSize + 1];
-int sequenceAt = 0;
-int prevSequenceSize = 0;
-
-int sequenceAtBit = 0;
-int inBinarySequence = 0;
 
 void baseLoop() {
   if (Serial.available()) {


#endif


void pulse(int length, int value)
{
  digitalWrite(out, value);
  digitalWrite(debug, value);
  time += 52 * length;
  delayMicroseconds(time - micros());
//  delayMicroseconds(length * 52);
}

// the loop routine runs over and over again forever:

        advanceBit();
      } break;
      case ';': {
#if 0
        Serial.print("Sending binary ");
        Serial.print(sequenceAt * 8);
        Serial.print("+");
        Serial.print(sequenceAtBit);
        Serial.println(" bits");
#endif        
        //sendBinarySequence(sequence, sequenceAt * 8 + sequenceAtBit);
        sendBinarySequenceHw();
        inBinarySequence = false;
      } break;
      default:
