Waiting for pulse to start (rising or falling edge) to start timing.

This commit is contained in:
David A. Mellis 2008-11-08 21:31:12 +00:00
parent 80fc987a94
commit 68e9d04f91
1 changed files with 5 additions and 0 deletions

View File

@ -44,6 +44,11 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
unsigned long numloops = 0;
unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
// wait for any previous pulse to end
while ((*portInputRegister(port) & bit) == stateMask)
if (numloops++ == maxloops)
return 0;
// wait for the pulse to start
while ((*portInputRegister(port) & bit) != stateMask)
if (numloops++ == maxloops)