Non-blocking Dallas sensors temperature conversion => lower power usage
This commit is contained in:
@@ -21,6 +21,8 @@ void setup()
|
|||||||
{
|
{
|
||||||
// Startup OneWire
|
// Startup OneWire
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
|
// requestTemperatures() will not block current thread
|
||||||
|
sensors.setWaitForConversion(false);
|
||||||
|
|
||||||
// Startup and initialize MySensors library. Set callback for incoming messages.
|
// Startup and initialize MySensors library. Set callback for incoming messages.
|
||||||
gw.begin();
|
gw.begin();
|
||||||
@@ -44,7 +46,12 @@ void loop()
|
|||||||
gw.process();
|
gw.process();
|
||||||
|
|
||||||
// Fetch temperatures from Dallas sensors
|
// Fetch temperatures from Dallas sensors
|
||||||
sensors.requestTemperatures();
|
sensors.requestTemperatures();
|
||||||
|
|
||||||
|
// query conversion time and sleep until conversion completed
|
||||||
|
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
|
||||||
|
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
|
||||||
|
gw.sleep(conversionTime);
|
||||||
|
|
||||||
// Read temperatures and send them to controller
|
// Read temperatures and send them to controller
|
||||||
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
|
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
|
||||||
@@ -62,6 +69,3 @@ void loop()
|
|||||||
}
|
}
|
||||||
gw.sleep(SLEEP_TIME);
|
gw.sleep(SLEEP_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user