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 // 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();
@@ -46,6 +48,11 @@ void loop()
// 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);
} }