perrociego:
By the way:
Doesnt if ((micros() - t) > 40) {} require something like else return DHTLIB_ERROR_TIMEOUT; ?
HI Marcello,
This line of code sets a 1 bit on a specific bit position (the cnt'th bit).
As the bits are preset to 0 on all bit positions they do not need to be explicitly cleared, e.g. like the code below would do.
if ((micros() - t) > 40) bitset(bits[idx], cnt);
else bitclear(bits[idx], cnt)
The timeout is guarded by the loops above this line with the variable loopCnt.
I have thought about a version of the DHT lib where timing and timeout is replaced by a proper call to micros(); That way the protocol would work on faster or slower CPU's. Problem with micros() however is that for a 16Mhz Arduino it has a granularity of 4 uSec. An 8MHZ version would have a micros() granularity of 8 or maybe even more. That would make it hard to do the short timing. (Imagine a tiny85 working on 1 MHz => would not work)
For the faster processors like the DUE, the lib would work probably better with micros() for timekeeping.