 }
 
 ISR(ADC_vect) {
+  static uint16_t pulseLength = 0;
+  static uint8_t lastADC = 127;
   TIFR1 = _BV(ICF1);
   PORTD |= _BV(2);
   dds.clockTick();
+  if(listening) {
+    pulseLength++;
+    if(ADCH >= adcHalf && lastADC < adcHalf) {
+      // Zero crossing, upward
+      recordedPulseLength = pulseLength;
+      recordedPulse = true;
+      pulseLength = 0;
+    }
+    if(minADC > ADCH) {
+      minADC = ADCH;
+    }
+    if(maxADC < ADCH) {
+      maxADC = ADCH;
+    }
+    lastADC = ADCH;
+  }
   PORTD &= ~_BV(2);
 }

            dds.setAmplitude((uint8_t)(freq&0xFF));
            Serial.print(F("New Amplitude: "));
            Serial.println((uint8_t)(freq&0xFF));
          }
          Serial.println("> ");
        }

          *freqBufferPtr = c;
          freqBufferPtr++;
        }
        if((c == '\n' || c == '\r') && freqBufferPtr != freqBuffer) {
          *freqBufferPtr = '\0';
          freqBufferPtr = freqBuffer;
          uint16_t freq = atoi(freqBuffer);
