 #endif
 }
 
+void startCapture() {
+  enableTimer();
+  intrHasCapture = true;
+  detachInterrupt(inInterrupt);
+}
+
 void dump() {
-  enableTimer();
   while (intrReading) {
     // wait
   }
+  intrHasCapture = false;
   for (int c = 0; c < intrOnes; ++c) {
     if (intrAtBit-- == 0) {
       intrAtBit = 7;
       --intrAtByte;
     }
   }
-  for (int atByte = 0, atBit = 0;
-       atByte != intrAtByte || atBit != intrAtBit;
-       (++atBit == 8) ? (atBit = 0, ++atByte) : 0) {
-    if (atByte && atBit == 0) {
-      Serial.print(" ");
+  if (intrAtByte || intrAtBit) {
+    for (int atByte = 0, atBit = 0;
+         atByte != intrAtByte || atBit != intrAtBit;
+         (++atBit == 8) ? (atBit = 0, ++atByte) : 0) {
+      if (atByte && atBit == 0) {
+        Serial.print(" ");
+      }
+      Serial.print((intrSamples[atByte] & (1 << atBit)) ? '1' : '0');
     }
-    Serial.print((intrSamples[atByte] & (1 << atBit)) ? '1' : '0');
+    if (intrZeroes == 20) {
+      Serial.print("/*..*/");
+    }
+    Serial.println();
   }
-  if (intrZeroes == 20) {
-    Serial.print("/*..*/");
-  }
-  Serial.println();
+  enableCaptureInterrupt();  
 }
 
 void loop() {
-  static bool started = false;
-  if (!started) {
-    int value = digitalRead(in);
-    if (value == HIGH) {
-      started = true;
-    }
-  } else {
-    int value = digitalRead(in);
-    if (value == LOW) {
-      dump();
-      started = false;
-    }
+  if (intrHasCapture) {
+    dump();
   }
 }

  intrOnes = 0;
  intrZeroes = 0;
  intrSamples[0] = 0;
  interrupts();
}

void disableTimer()


void enableTimer()
{
  TIMSK1 |= (1 << TOIE1);
  intrReading = true;
  intrFirst = true;
