Skip to content

Commit a3d1dc7

Browse files
committed
Added option for converting to Fahrenheit
1 parent 8f46f27 commit a3d1dc7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

DHT.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ void DHT::begin(void) {
1919
_lastreadtime = 0;
2020
}
2121

22-
float DHT::readTemperature(void) {
22+
//boolean S == Scale. True == Farenheit; False == Celcius
23+
float DHT::readTemperature(bool S) {
2324
float f;
2425

2526
if (read()) {
2627
switch (_type) {
2728
case DHT11:
2829
f = data[2];
30+
if(S)
31+
f = convertCtoF(f);
32+
2933
return f;
3034
case DHT22:
3135
case DHT21:
@@ -35,6 +39,8 @@ float DHT::readTemperature(void) {
3539
f /= 10;
3640
if (data[2] & 0x80)
3741
f *= -1;
42+
if(S)
43+
f = convertCtoF(f);
3844

3945
return f;
4046
}
@@ -43,6 +49,10 @@ float DHT::readTemperature(void) {
4349
return NAN;
4450
}
4551

52+
float DHT::convertCtoF(float c) {
53+
return c * 9 / 5 + 32;
54+
}
55+
4656
float DHT::readHumidity(void) {
4757
float f;
4858
if (read()) {

0 commit comments

Comments
 (0)