Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "esphome.h"
- #include <SHT1x.h>
- class Sht15 : public PollingComponent
- {
- public:
- Sensor *temperature_sensor = new Sensor();
- Sensor *humidity_sensor = new Sensor();
- Sht15() : PollingComponent(60000) {}
- void setup() override
- {
- this->sht1x_ = new SHT1x(dataPin_, clockPin_);
- }
- void update() override
- {
- float temp_c = this->sht1x_->readTemperatureC();
- float humidity = this->sht1x_->readHumidity();
- temperature_sensor->publish_state(temp_c);
- humidity_sensor->publish_state(humidity);
- }
- protected:
- SHT1x *sht1x_;
- int dataPin_ = 2;
- int clockPin_ = 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement