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