File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222
2323#include " dht.h"
2424
25- #define TIMEOUT 10000
25+ #define TIMEOUT ( F_CPU / 1600 ) // unsigned int in code, for higher CPU speeds this might exceed MAXINT.
2626
2727// ///////////////////////////////////////////////////
2828//
@@ -62,29 +62,7 @@ int dht::read11(uint8_t pin)
6262// DHTLIB_ERROR_TIMEOUT
6363int dht::read21 (uint8_t pin)
6464{
65- // READ VALUES
66- int rv = read (pin);
67- if (rv != DHTLIB_OK )
68- {
69- humidity = DHTLIB_INVALID_VALUE ; // invalid value, or is NaN prefered?
70- temperature = DHTLIB_INVALID_VALUE ; // invalid value
71- return rv; // propagate error value
72- }
73-
74- // CONVERT AND STORE
75- humidity = bits[0 ] + bits[1 ] * 0.00390625 ; // == 1/256.0
76- temperature = (bits[2 ] & 0x7F ) + bits[3 ] * 0.00390625 ;
77-
78- if (bits[2 ] & 0x80 ) // negative temperature
79- {
80- temperature = -temperature;
81- }
82-
83- // TEST CHECKSUM
84- uint8_t sum = bits[0 ] + bits[1 ] + bits[2 ] + bits[3 ];
85- if (bits[4 ] != sum) return DHTLIB_ERROR_CHECKSUM ;
86-
87- return DHTLIB_OK ;
65+ return read22 (pin); // dataformat identical to DHT22
8866}
8967
9068// return values:
Original file line number Diff line number Diff line change 1313dht DHT ;
1414
1515#define DHT11_PIN 4
16- #define DHT22_PIN 5
16+ #define DHT21_PIN 5
17+ #define DHT22_PIN 6
1718
1819void setup ()
1920{
@@ -55,7 +56,7 @@ void loop()
5556
5657 // READ DATA
5758 Serial.print (" DHT21, \t " );
58- int chk = DHT . read21(DHT21_PIN );
59+ chk = DHT .read21 (DHT21_PIN );
5960 switch (chk)
6061 {
6162 case DHTLIB_OK :
You can’t perform that action at this time.
0 commit comments