11//
22// FILE: dht.cpp
33// AUTHOR: Rob Tillaart
4- // VERSION: 0.1.10
4+ // VERSION: 0.1.11
55// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
66// URL: http://arduino.cc/playground/Main/DHTLib
77//
88// HISTORY:
9+ // 0.1.11 renamed DHTLIB_TIMEOUT
910// 0.1.10 optimized faster WAKEUP + TIMEOUT
1011// 0.1.09 optimize size: timeout check + use of mask
1112// 0.1.08 added formula for timeout based upon clockspeed
2526
2627#include " dht.h"
2728
28- // max timeout is 100usec.
29- // For a 16Mhz proc that is max 1600 clock cycles
30- // loops using TIMEOUT use at least 4 clock cycli
31- // so 100 us takes max 400 loops
32- // so by dividing F_CPU by 40000 we "fail" as fast as possible
33- #define TIMEOUT (F_CPU/40000 )
34-
35-
3629// ///////////////////////////////////////////////////
3730//
3831// PUBLIC
@@ -135,13 +128,13 @@ int dht::read(uint8_t pin, uint8_t wakeupDelay)
135128 pinMode (pin, INPUT);
136129
137130 // GET ACKNOWLEDGE or TIMEOUT
138- unsigned int loopCnt = TIMEOUT ;
131+ unsigned int loopCnt = DHTLIB_TIMEOUT ;
139132 while (digitalRead (pin) == LOW)
140133 {
141134 if (--loopCnt == 0 ) return DHTLIB_ERROR_TIMEOUT;
142135 }
143136
144- loopCnt = TIMEOUT ;
137+ loopCnt = DHTLIB_TIMEOUT ;
145138 while (digitalRead (pin) == HIGH)
146139 {
147140 if (--loopCnt == 0 ) return DHTLIB_ERROR_TIMEOUT;
@@ -150,15 +143,15 @@ int dht::read(uint8_t pin, uint8_t wakeupDelay)
150143 // READ THE OUTPUT - 40 BITS => 5 BYTES
151144 for (uint8_t i = 0 ; i < 40 ; i++)
152145 {
153- loopCnt = TIMEOUT ;
146+ loopCnt = DHTLIB_TIMEOUT ;
154147 while (digitalRead (pin) == LOW)
155148 {
156149 if (--loopCnt == 0 ) return DHTLIB_ERROR_TIMEOUT;
157150 }
158151
159152 unsigned long t = micros ();
160153
161- loopCnt = TIMEOUT ;
154+ loopCnt = DHTLIB_TIMEOUT ;
162155 while (digitalRead (pin) == HIGH)
163156 {
164157 if (--loopCnt == 0 ) return DHTLIB_ERROR_TIMEOUT;
0 commit comments