123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #ifndef DHT_H
- #define DHT_H
- #include "Arduino.h"
- #define DEBUG_PRINTER \
- Serial
- #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
- static const uint8_t DHT11{11};
- static const uint8_t DHT12{12};
- static const uint8_t DHT21{21};
- static const uint8_t DHT22{22};
- static const uint8_t AM2301{21};
- #if defined(TARGET_NAME) && (TARGET_NAME == ARDUINO_NANO33BLE)
- #ifndef microsecondsToClockCycles
- #define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L))
- #endif
- #endif
- class DHT {
- public:
- DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
- void begin(uint8_t usec = 55);
- float readTemperature(bool S = false, bool force = false);
- float convertCtoF(float);
- float convertFtoC(float);
- float computeHeatIndex(bool isFahrenheit = true);
- float computeHeatIndex(float temperature, float percentHumidity,
- bool isFahrenheit = true);
- float readHumidity(bool force = false);
- bool read(bool force = false);
- private:
- uint8_t data[5];
- uint8_t _pin, _type;
- #ifdef __AVR
-
-
-
- uint8_t _bit, _port;
- #endif
- uint32_t _lastreadtime, _maxcycles;
- bool _lastresult;
- uint8_t pullTime;
- uint32_t expectPulse(bool level);
- };
- class InterruptLock {
- public:
- InterruptLock() {
- #if !defined(ARDUINO_ARCH_NRF52)
- noInterrupts();
- #endif
- }
- ~InterruptLock() {
- #if !defined(ARDUINO_ARCH_NRF52)
- interrupts();
- #endif
- }
- };
- #endif
|