mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Waiting for pulse to start (rising or falling edge) to start timing.
This commit is contained in:
@ -44,6 +44,11 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
|
|||||||
unsigned long numloops = 0;
|
unsigned long numloops = 0;
|
||||||
unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
|
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
|
// wait for the pulse to start
|
||||||
while ((*portInputRegister(port) & bit) != stateMask)
|
while ((*portInputRegister(port) & bit) != stateMask)
|
||||||
if (numloops++ == maxloops)
|
if (numloops++ == maxloops)
|
||||||
|
Reference in New Issue
Block a user