-
Notifications
You must be signed in to change notification settings - Fork 0
/
dht11.h
38 lines (30 loc) · 856 Bytes
/
dht11.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef DHT11_H
#define DHT11_H
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define DHT_LIB_VERSION "0.1.13"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
#define DHTLIB_INVALID_VALUE -999
#define DHTLIB_DHT11_WAKEUP 18
#define DHTLIB_DHT_WAKEUP 1
// max timeout is 100usec.
// For a 16Mhz proc that is max 1600 clock cycles
// loops using TIMEOUT use at least 4 clock cycli
// so 100 us takes max 400 loops
// so by dividing F_CPU by 40000 we "fail" as fast as possible
#define DHTLIB_TIMEOUT (F_CPU/40000)
class dht11 {
public:
int read(uint8_t pin);
double humidity;
double temperature;
private:
uint8_t bits[5]; // buffer to receive data
int _readSensor(uint8_t pin, uint8_t wakeupDelay);
};
#endif