01_humidity.ino 535 B

123456789101112131415161718192021222324252627282930
  1. #include <Adafruit_AHTX0.h>
  2. Adafruit_AHTX0 aht;
  3. struct {
  4. public:
  5. float temperature;
  6. float humidity;
  7. } HumTemp;
  8. void initHumidity() {
  9. debugln("Initializing humidity sensor");
  10. if (!aht.begin()) {
  11. Serial.println("Could not initialize humidity sensor");
  12. // TODO: Turn on the LED or screen or something
  13. ERR;
  14. }
  15. debugln("Initialized humidity sensor");
  16. }
  17. void updateHumidity() {
  18. sensors_event_t hum,
  19. temp;
  20. aht.getEvent(&hum, &temp);
  21. HumTemp.temperature = temp.temperature;
  22. HumTemp.humidity = hum.relative_humidity;
  23. }