Implementation of pulseIn