AskSin++
Sht31.h
1 //- -----------------------------------------------------------------------------------------------------------------------
2 // AskSin++
3 // 2018-11-02 jp112sdl Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
4 //- -----------------------------------------------------------------------------------------------------------------------
5 
6 #ifndef __SENSORS_SHT31_h__
7 #define __SENSORS_SHT31_h__
8 
9 #include <Sensors.h>
10 #include <Wire.h>
11 #include <Adafruit_SHT31.h>
12 
13 namespace as {
14 
15 //https://github.com/adafruit/Adafruit_SHT31
16 template <uint8_t ADDRESS=0x44>
17 class Sht31 : public Temperature, public Humidity {
18  Adafruit_SHT31 _sht31;
19 public:
20  Sht31 () {}
21 
22  void init () {
23  _present = _sht31.begin(ADDRESS);
24  DPRINT(F("SHT31 "));
25  if (_present) {
26  DPRINTLN(F("OK"));
27  } else {
28  DPRINTLN(F("ERROR"));
29  }
30  }
31 
32  bool measure (__attribute__((unused)) bool async=false) {
33  if( present() == true ) {
34  _temperature = _sht31.readTemperature() * 10;
35  _humidity = _sht31.readHumidity();
36  return true;
37  }
38  return false;
39  }
40 
41 };
42 
43 }
44 
45 #endif
as::Sht31
Definition: Sht31.h:17
as::Humidity
Definition: Sensors.h:39
as::Temperature
Definition: Sensors.h:30