forked from RoelKroes/TBTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempSensor.ino
39 lines (32 loc) · 1.07 KB
/
tempSensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void setup2() {
// Start up the library
sensors.begin();
// Grab a count of devices on the wire
numberOfDevices = sensors.getDeviceCount();
// locate devices on the bus
// report parasite power requirements
// Loop through each device, print out address
for (int i = 0; i < 1; i++)
{
// Search the wire for address
if (sensors.getAddress(tempDeviceAddress, i))
{
// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
} else {
}
}
}
float getTemperature(DeviceAddress deviceAddress)
{
sensors.requestTemperatures();
sensors.getAddress(tempDeviceAddress, 0);
// method 1 - slower
//Serial.print("Temp C: ");
//Serial.print(sensors.getTempC(deviceAddress));
//Serial.print(" Temp F: ");
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
// method 2 - faster
float tempC = sensors.getTempC(deviceAddress);
return tempC;
}