change to timeout of pulseIn() function

Hello all,

In the arduino docs, it seems to indicate that the timeout value passed to the pulseIn() function, will be the timeout before the pulse starts. However, in the implementation I have (1.0) it appears that the function will timeout even during the pulse if the timeout is hit. Did this functionality change at some point? It appears to have because I downloaded some older code that uses the pulseIn() function that appears to depend upon the fact that if the timeout happens during the pulse, the function will still measure it. Can anyone verify this change? Thanks!

Josh

Cannot confirm it as all version I have do this the same way.

Checking the timeout in every phase makes sense as otherwise pulseIn() could block forever.

That said you are free to patch the 1.0 distri :slight_smile:

I agree about the wisdom of having the timeout not allow the function to block forever, however, there's also reason to have a separate timeout for how long till the pulse starts. I suggest having two timeout values, obviously both of them could default to the same value and with default parameters it wouldn't have to break anyone's code. If I patch it would it have a good probability of being included?

The timeout applies for the entire function - before and during the pulse.

"The timeout applies for the entire function - before and during the pulse."

Right, I can see that is clear in the code. I have some sample code I downloaded that suggests that the function didn't always operate like that, and the docs seem to corroborate in their description as well. So at a minimum the docs need to be updated which state, "timeout (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)." But I'd also like confirmation that the function used to operate differently, with the timeout only applying to before the pulse starts. Furthermore, I'd suggest adding another parameter to the function which allows specifying two timeouts, the second timeout parameter being the timeout before the pulse starts. This can be very useful to allow quickly polling for a pulse, even if the pulse itself may be long. It wouldn't break any existing code due to putting the new parameter at the end of the list and giving it a default value...