2015-06-27 01:14:17 +03:00
|
|
|
/* DHT library
|
|
|
|
|
|
|
|
MIT license
|
|
|
|
written by Adafruit Industries
|
|
|
|
*/
|
|
|
|
#ifndef DHT_H
|
|
|
|
#define DHT_H
|
|
|
|
|
|
|
|
#if ARDUINO >= 100
|
|
|
|
#include "Arduino.h"
|
|
|
|
#else
|
|
|
|
#include "WProgram.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Uncomment to enable printing out nice debug messages.
|
|
|
|
//#define DHT_DEBUG
|
|
|
|
|
|
|
|
// Define where debug output will be printed.
|
|
|
|
#define DEBUG_PRINTER Serial
|
|
|
|
|
|
|
|
// Setup debug printing macros.
|
|
|
|
#ifdef DHT_DEBUG
|
|
|
|
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
|
|
|
|
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
|
|
|
|
#else
|
|
|
|
#define DEBUG_PRINT(...) {}
|
|
|
|
#define DEBUG_PRINTLN(...) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Define types of sensors.
|
|
|
|
#define DHT11 11
|
2017-12-12 09:20:26 +03:00
|
|
|
#define DHT12 12
|
2015-06-27 01:14:17 +03:00
|
|
|
#define DHT22 22
|
|
|
|
#define DHT21 21
|
|
|
|
#define AM2301 21
|
|
|
|
|
|
|
|
|
|
|
|
class DHT {
|
|
|
|
public:
|
|
|
|
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
|
|
|
|
void begin(void);
|
2015-07-24 18:37:24 +03:00
|
|
|
float readTemperature(bool S=false, bool force=false);
|
2015-06-27 01:14:17 +03:00
|
|
|
float convertCtoF(float);
|
|
|
|
float convertFtoC(float);
|
2018-07-30 21:27:30 +03:00
|
|
|
float computeHeatIndex(bool isFahrenheit=true);
|
2015-06-27 01:56:04 +03:00
|
|
|
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
|
2015-07-24 18:37:24 +03:00
|
|
|
float readHumidity(bool force=false);
|
2018-06-27 20:18:17 +03:00
|
|
|
bool read(bool force=false);
|
2015-06-27 01:14:17 +03:00
|
|
|
|
|
|
|
private:
|
2015-07-24 19:08:47 +03:00
|
|
|
uint8_t data[5];
|
2015-10-13 07:30:01 +03:00
|
|
|
uint8_t _pin, _type;
|
|
|
|
#ifdef __AVR
|
|
|
|
// Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
|
|
|
|
// for the digital pin connected to the DHT. Other platforms will use digitalRead.
|
|
|
|
uint8_t _bit, _port;
|
|
|
|
#endif
|
2015-07-22 22:13:56 +03:00
|
|
|
uint32_t _lastreadtime, _maxcycles;
|
2015-06-27 01:14:17 +03:00
|
|
|
bool _lastresult;
|
|
|
|
|
|
|
|
uint32_t expectPulse(bool level);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-07-02 03:53:53 +03:00
|
|
|
class InterruptLock {
|
|
|
|
public:
|
|
|
|
InterruptLock() {
|
2018-08-14 22:44:40 +03:00
|
|
|
#if !defined(ARDUINO_ARCH_NRF52)
|
2015-07-02 03:53:53 +03:00
|
|
|
noInterrupts();
|
2018-08-14 22:44:40 +03:00
|
|
|
#endif
|
2015-07-02 03:53:53 +03:00
|
|
|
}
|
|
|
|
~InterruptLock() {
|
2018-08-14 22:44:40 +03:00
|
|
|
#if !defined(ARDUINO_ARCH_NRF52)
|
2015-07-02 03:53:53 +03:00
|
|
|
interrupts();
|
2018-08-14 22:44:40 +03:00
|
|
|
#endif
|
2015-07-02 03:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-06-27 01:14:17 +03:00
|
|
|
#endif
|