File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 24
24
2013-06-10: Initial version
25
25
2013-06-12: Refactored code
26
26
2013-07-01: Add a resetTimer method
27
+ 2016-07-20: Add force parameter - Torben Woltjen (mozzbozz)
27
28
******************************************************************/
28
29
29
30
#include " DHT.h"
@@ -108,13 +109,15 @@ const char *DHT::getStatusString() {
108
109
109
110
#endif
110
111
111
- void DHT::readSensor ()
112
+ void DHT::readSensor (bool force )
112
113
{
113
114
// Make sure we don't poll the sensor too often
114
115
// - Max sample rate DHT11 is 1 Hz (duty cicle 1000 ms)
115
116
// - Max sample rate DHT22 is 0.5 Hz (duty cicle 2000 ms)
117
+ // If 'force' is true, the user has to take care of this -> this way, the
118
+ // microcontroller can be set to sleep where it doesn't increase millis().
116
119
unsigned long startTime = millis ();
117
- if ( (unsigned long )(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L ) ) {
120
+ if ( !force && (unsigned long )(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L ) ) {
118
121
return ;
119
122
}
120
123
lastReadTime = startTime;
Original file line number Diff line number Diff line change 24
24
2013-06-10: Initial version
25
25
2013-06-12: Refactored code
26
26
2013-07-01: Add a resetTimer method
27
+ 2016-07-20: Add force parameter - Torben Woltjen (mozzbozz)
27
28
******************************************************************/
28
29
29
30
#ifndef dht_h
@@ -58,6 +59,7 @@ class DHT
58
59
void setup (uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);
59
60
void resetTimer ();
60
61
62
+ void readSensor (bool force=false );
61
63
float getTemperature ();
62
64
float getHumidity ();
63
65
@@ -80,8 +82,6 @@ class DHT
80
82
static float toCelsius (float fromFahrenheit) { return (fromFahrenheit - 32.0 ) / 1.8 ; };
81
83
82
84
protected:
83
- void readSensor ();
84
-
85
85
float temperature;
86
86
float humidity;
87
87
You can’t perform that action at this time.
0 commit comments