File tree Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ float DHT::readTemperature(bool S) {
46
46
return f;
47
47
}
48
48
}
49
- Serial.print (" Read fail" );
50
49
return NAN;
51
50
}
52
51
@@ -70,7 +69,6 @@ float DHT::readHumidity(void) {
70
69
return f;
71
70
}
72
71
}
73
- Serial.print (" Read fail" );
74
72
return NAN;
75
73
}
76
74
Original file line number Diff line number Diff line change @@ -32,25 +32,26 @@ void loop() {
32
32
float t = dht.readTemperature ();
33
33
// Read temperature as Fahrenheit
34
34
float f = dht.readTemperature (true );
35
+
36
+ // Check if any reads failed and exit early (to try again).
37
+ if (isnan (h) || isnan (t) || isnan (f)) {
38
+ Serial.println (" Failed to read from DHT sensor!" );
39
+ return ;
40
+ }
41
+
35
42
// Compute heat index
36
43
// Must send in temp in Fahrenheit!
37
44
float hi = dht.computeHeatIndex (f, h);
38
45
39
- // check if returns are valid, if they are NaN (not a number) then something went wrong!
40
- if (isnan (t) || isnan (h)) {
41
- Serial.println (" Failed to read from DHT" );
42
- } else {
43
- Serial.print (" Humidity: " );
44
- Serial.print (h);
45
- Serial.print (" %\t " );
46
- Serial.print (" Temperature: " );
47
- Serial.print (t);
48
- Serial.print (" *C " );
49
- Serial.print (f);
50
- Serial.print (" *F\t " );
51
- Serial.print (" Heat index: " );
52
- Serial.print (hi);
53
- Serial.println (" *F" );
54
-
55
- }
46
+ Serial.print (" Humidity: " );
47
+ Serial.print (h);
48
+ Serial.print (" %\t " );
49
+ Serial.print (" Temperature: " );
50
+ Serial.print (t);
51
+ Serial.print (" *C " );
52
+ Serial.print (f);
53
+ Serial.print (" *F\t " );
54
+ Serial.print (" Heat index: " );
55
+ Serial.print (hi);
56
+ Serial.println (" *F" );
56
57
}
You can’t perform that action at this time.
0 commit comments