   }
   #endif
   
-  triggered = false;
+  triggered = false; //wait for another interrupt
 }
-
-ISR(TIMER1_CAPT_vect) {
-  counter = ICR1;
-  triggered = true;
-}

uint16_t rcChannels[RC_CHANNELS_COUNT];
uint8_t chan = 0; // current channel

void setup() {
  pinMode(PPM_CAPTURE_PIN, INPUT_PULLUP);

  // Input Capture setup
  // ICNC1: =0 Disable Input Capture Noise Canceler to prevent delay in reading

  TIFR1 = (1<<ICF1); // clear pending
  TIMSK1 = (1<<ICIE1); // and enable
  
	USBGamepad.begin(rcChannels);  //send empty USB report

#ifdef DEBUG
  timer = millis(); // start timer
	Serial.begin(115200);
#endif
  sei(); //enable global interrupts
}

void loop(){
  if (!triggered) //wait for interrupt
    return;  
  pulse = (counter - last) / TIMER_COUNT_DIVIDER; //pulse width
  last = counter; //store
  if(pulse > (NEWFRAME_PULSE_WIDTH)) {
    chan = 0;  // new data frame detected, start again    
    if (first) { //discard first frame data because it may be incomplete 
      first = false;
      triggered = false;
      return;
    } else 
    {
      USBGamepad.write(rcChannels); //send usb report with channels data
    }
  }
  else {
    if(pulse > (MIN_PULSE_WIDTH - THRESHOLD) 
      && pulse < (MAX_PULSE_WIDTH + THRESHOLD) 
      && chan < RC_CHANNELS_COUNT && !first) 
    {
      rcChannels[chan] = pulse; //store detected value      
    }
    chan++; //no value detected within expected range, move to next channel
  }
