Advertisement
jesserockz

sht1x.h

Sep 27th, 2020
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include "esphome.h"
  2. #include <SHT1x.h>
  3.  
  4. class Sht15 : public PollingComponent
  5. {
  6. public:
  7.   Sensor *temperature_sensor = new Sensor();
  8.   Sensor *humidity_sensor = new Sensor();
  9.  
  10.   Sht15() : PollingComponent(60000) {}
  11.  
  12.   void setup() override
  13.   {
  14.     this->sht1x_ = new SHT1x(dataPin_, clockPin_);
  15.   }
  16.  
  17.   void update() override
  18.   {
  19.     float temp_c = this->sht1x_->readTemperatureC();
  20.     float humidity = this->sht1x_->readHumidity();
  21.     temperature_sensor->publish_state(temp_c);
  22.     humidity_sensor->publish_state(humidity);
  23.   }
  24.  
  25.  protected:
  26.   SHT1x *sht1x_;
  27.   int dataPin_ = 2;
  28.   int clockPin_ = 0;
  29. };
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement