This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup(void)
|
||||
@@ -22,10 +22,10 @@ void setup(void)
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
{
|
||||
// Request temperature conversion (traditional)
|
||||
Serial.println("Before blocking requestForConversion");
|
||||
unsigned long start = millis();
|
||||
unsigned long start = millis();
|
||||
|
||||
sensors.requestTemperatures();
|
||||
|
||||
@@ -33,34 +33,34 @@ void loop(void)
|
||||
Serial.println("After blocking requestForConversion");
|
||||
Serial.print("Time used: ");
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
// get temperature
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println("\n");
|
||||
|
||||
|
||||
// Request temperature conversion - non-blocking / async
|
||||
Serial.println("Before NON-blocking/async requestForConversion");
|
||||
start = millis();
|
||||
start = millis();
|
||||
sensors.setWaitForConversion(false); // makes it async
|
||||
sensors.requestTemperatures();
|
||||
sensors.setWaitForConversion(true);
|
||||
stop = millis();
|
||||
Serial.println("After NON-blocking/async requestForConversion");
|
||||
Serial.print("Time used: ");
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
// 9 bit resolution by default
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
// 9 bit resolution by default
|
||||
// Note the programmer is responsible for the right delay
|
||||
// we could do something usefull here instead of the delay
|
||||
int resolution = 9;
|
||||
delay(750/ (1 << (12-resolution)));
|
||||
|
||||
delay(750 / (1 << (12 - resolution)));
|
||||
|
||||
// get temperature
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println("\n\n\n\n");
|
||||
|
||||
delay(5000);
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println("\n\n\n\n");
|
||||
|
||||
delay(1500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user