1/* DHT library
2
3MIT license
4written by Adafruit Industries
5*/
6#ifndef DHT_H
7#define DHT_H
8
9#if ARDUINO >= 100
10 #include "Arduino.h"
11#else
12 #include "WProgram.h"
13#endif
14
15
16// Uncomment to enable printing out nice debug messages.
17//#define DHT_DEBUG
18
19// Define where debug output will be printed.
20#define DEBUG_PRINTER Serial
21
22// Setup debug printing macros.
23#ifdef DHT_DEBUG
24 #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
25 #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
26#else
27 #define DEBUG_PRINT(...) {}
28 #define DEBUG_PRINTLN(...) {}
29#endif
30
31// Define types of sensors.
32#define DHT11 11
33#define DHT22 22
34#define DHT21 21
35#define AM2301 21
36
37
38class DHT {
39 public:
40 DHT(uint8_t pin, uint8_t type, uint8_t count=6);
41 void begin(void);
42 float readTemperature(bool S=false, bool force=false);
43 float convertCtoF(float);
44 float convertFtoC(float);
45 float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
46 float readHumidity(bool force=false);
47 boolean read(bool force=false);
48
49 private:
50 uint8_t data[5];
51 uint8_t _pin, _type;
52 #ifdef __AVR
53 // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
54 // for the digital pin connected to the DHT. Other platforms will use digitalRead.
55 uint8_t _bit, _port;
56 #endif
57 uint32_t _lastreadtime, _maxcycles;
58 bool _lastresult;
59
60 uint32_t expectPulse(bool level);
61
62};
63
64class InterruptLock {
65 public:
66 InterruptLock() {
67 noInterrupts();
68 }
69 ~InterruptLock() {
70 interrupts();
71 }
72
73};
74
75#endif