File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,17 @@ void DHT::begin(void) {
19
19
_lastreadtime = 0 ;
20
20
}
21
21
22
- float DHT::readTemperature (void ) {
22
+ // boolean S == Scale. True == Farenheit; False == Celcius
23
+ float DHT::readTemperature (bool S) {
23
24
float f;
24
25
25
26
if (read ()) {
26
27
switch (_type) {
27
28
case DHT11:
28
29
f = data[2 ];
30
+ if (S)
31
+ f = convertCtoF (f);
32
+
29
33
return f;
30
34
case DHT22:
31
35
case DHT21:
@@ -35,6 +39,8 @@ float DHT::readTemperature(void) {
35
39
f /= 10 ;
36
40
if (data[2 ] & 0x80 )
37
41
f *= -1 ;
42
+ if (S)
43
+ f = convertCtoF (f);
38
44
39
45
return f;
40
46
}
@@ -43,6 +49,10 @@ float DHT::readTemperature(void) {
43
49
return NAN;
44
50
}
45
51
52
+ float DHT::convertCtoF (float c) {
53
+ return c * 9 / 5 + 32 ;
54
+ }
55
+
46
56
float DHT::readHumidity (void ) {
47
57
float f;
48
58
if (read ()) {
You can’t perform that action at this time.
0 commit comments