DHT.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef DHT_H
  2. #define DHT_H
  3. #if ARDUINO >= 100
  4. #include "Arduino.h"
  5. #else
  6. #include "WProgram.h"
  7. #endif
  8. // WioLTE STM32F405 compatibility
  9. #define STM32F405
  10. // 8 MHz(ish) AVR ---------------------------------------------------------
  11. #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL)
  12. #define COUNT 3
  13. // 16 MHz(ish) AVR --------------------------------------------------------
  14. #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L)
  15. #define COUNT 6
  16. #elif defined(STM32F405)
  17. #define COUNT 40
  18. #else
  19. #error "CPU SPEED NOT SUPPORTED"
  20. #endif
  21. /* DHT library
  22. MIT license
  23. written by Adafruit Industries
  24. */
  25. // how many timing transitions we need to keep track of. 2 * number bits + extra
  26. #define MAXTIMINGS 85
  27. #define DHT11 11
  28. #define DHT22 22
  29. #define DHT21 21
  30. #define AM2301 21
  31. class DHT {
  32. private:
  33. uint8_t data[6];
  34. uint8_t _pin, _type, _count;
  35. boolean read(void);
  36. unsigned long _lastreadtime;
  37. boolean firstreading;
  38. public:
  39. DHT(uint8_t pin, uint8_t type, uint8_t count=COUNT);
  40. void begin(void);
  41. float readTemperature(bool S=false);
  42. float convertCtoF(float);
  43. float readHumidity(void);
  44. };
  45. #endif