1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00

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 542a64fac1
commit e79b319fd1

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)