How to change function

Hello everybody!

After updating Arduino software to 0013 version, pulseIn functions starts working wrong for me. In release notes we can found this note:

  • Modifying pulseIn() to wait for a transition to start timing (i.e. ignoring
    any pulse that had already started when the function was called).

In Arduino version <= 12 it working fine for me, because i need to start timing pulse that had already started. So question is how to change function body in Arduino 14?

I am using mac os x.

I have not actually tried it but if you drop the code below into a sketch and call OldpulseIn you should get the old 0012 functionality

#include "wiring_private.h"
#include "pins_arduino.h" 
unsigned long OldpulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
      uint8_t bit = digitalPinToBitMask(pin);
      uint8_t port = digitalPinToPort(pin);
      uint8_t stateMask = (state ? bit : 0);
      unsigned long width = 0; // keep initialization out of time critical area
      unsigned long numloops = 0;
      unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
      // wait for the pulse to start
      while ((*portInputRegister(port) & bit) != stateMask)
            if (numloops++ == maxloops)
                  return 0;
      // wait for the pulse to stop
      while ((*portInputRegister(port) & bit) == stateMask)
      return clockCyclesToMicroseconds(width * 10 + 16);