Replace delay with delayMicroseconds to let it work while interruppts are disabeled.

In multihreaded environment (I used NilRTOS) its usefull to disable interruppts while reading the sensors. However delay() requires interrupts to be enabled. If you read more than one sensor in a sequence the 2nd one gets spurious DHTLIB_ERROR_CONNECT errors. Timing issues with the wakeup delay().
They don't used to happen it interrupts are enabled. Replacing delay() with delayMicroseconds() solved this issue.
This commit is contained in:
Peter Hahn 2015-10-11 22:56:25 +02:00
parent bd5f923158
commit 174a065598

View File

@ -124,7 +124,7 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW); // T-be
delay(wakeupDelay);
delayMicroseconds(wakeupDelay*1000);
digitalWrite(pin, HIGH); // T-go
pinMode(pin, INPUT);
@ -197,4 +197,4 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
}
//
// END OF FILE
//
//