Go Down

Topic: removing delay() in DallasTemperature.cpp (Read 798 times) previous topic - next topic

sync

Jul 26, 2009, 01:44 pm Last Edit: Jul 26, 2009, 01:47 pm by sync Reason: 1
My project require the use of a Dallas temperature sensor and the my program already execute other functions that can not be delayed at all. The Dallas need a 1 second delay everytime a request is made. How DallasTemperature.cpp program can be modified to not use delay() but millis() instead ?

http://milesburton.com/downloads/Arduino/DallasTemperature/DallasTemperature.rar

Code: [Select]
// Send command
void DallasTemperature::beginCommunication(void)
{
 pDataWire->reset();
 pDataWire->select(arSlaveAddr);
 pDataWire->write(STARTCONVO,1);         // start conversion, with parasite power on at the end
 delay(1000);
}

Rusty in Texas

You could save the current millis() value and add 1000 (although 750
will be fine) to it after  the StartConversion has been commanded.
Afterwards, the Arduino can continue doing what it needs to do,
periodically checking the value of millis() to see if the delay has
expired, and read the temperature then.   The temperature value
will be retained by the 18x20 until the Arduino has a chance to read it.

Go Up