 // target : Arduino Mega (ATMega2560)
 // note   : - use timer1 for 0.5 uS accuracy time measure 
 //            (arduino core micros() is just 4us accuracy).
-//          - signal to detect must be wire on pin 2.
+//          - signal to detect must be wire on pin 19 (Rx of Serial1).
 //          - use bitlash for console manager (see https://github.com/billroy/bitlash)
 //          - use Timer for schedule tasks (see  https://github.com/JChristensen/Timer)
 

  sei();
  // init bitlash
  initBitlash(57600);
  // add bitlash function
  addBitlashFunction("raw", (bitlash_function) printRAW);
  addBitlashFunction("bd", (bitlash_function) printBaud);
  // fill in the UART file descriptor with pointer to writer
  fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
  // standard output device STDOUT is uart
  stdout = &uartout ;
  // launch timer task
  int updateJob = t.every(500, update_time_buffer);
  // IO init

  attachInterrupt(SERIAL_IN_INT, isr_serial_change, CHANGE);
}

// call if data available on Serial1
void serialEvent1() {
  while (Serial1.available()) {
    // read rx byte
    char inChar = (char)Serial1.read();
    // add rx byte to array
    rx_bytes[rx_byte_index].value = inChar;
    rx_bytes[rx_byte_index].time  = millis();
    if (++rx_byte_index >= ROW_COUNT(rx_bytes))
      rx_byte_index = 0;
  }
}

void loop(void) {
  // bitlash job
  runBitlash();
