mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
04905bc5cd
This allows forcing a read, even if the previous read was less than 2 seconds ago. This is useful in cases where the millis() timer is not reliable, such as when sleeping. In this case, it is up to the caller to ensure that at least 2 seconds elapse between calls with force set to true.
72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
/* 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
|
|
#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);
|
|
float readTemperature(bool S=false, bool force=false);
|
|
float convertCtoF(float);
|
|
float convertFtoC(float);
|
|
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
|
|
float readHumidity(bool force=false);
|
|
boolean read(bool force=false);
|
|
|
|
private:
|
|
uint8_t data[6];
|
|
uint8_t _pin, _type, _bit, _port;
|
|
uint32_t _lastreadtime, _maxcycles;
|
|
bool _firstreading;
|
|
bool _lastresult;
|
|
|
|
uint32_t expectPulse(bool level);
|
|
|
|
};
|
|
|
|
class InterruptLock {
|
|
public:
|
|
InterruptLock() {
|
|
noInterrupts();
|
|
}
|
|
~InterruptLock() {
|
|
interrupts();
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|