Non-blocking Dallas sensors temperature conversion => lower power usage

This commit is contained in:
Robo Print
2015-06-27 23:27:35 +02:00
parent e47e596075
commit dffec69462
@@ -21,6 +21,8 @@ void setup()
{
// Startup OneWire
sensors.begin();
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
// Startup and initialize MySensors library. Set callback for incoming messages.
gw.begin();
@@ -44,7 +46,12 @@ void loop()
gw.process();
// 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
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
@@ -62,6 +69,3 @@ void loop()
}
gw.sleep(SLEEP_TIME);
}