Page 135 - Programming the Photon Getting Started With the Internet of Things
P. 135
Figure 6.12 Searching for the spark-dallas-temperature library.
After we define the digital pin for the sensor, we must tell the program to start the one-
wire serial bus on that particular pin. The next line directly below that tells the library to
use that particular interface when communicating serial data to the temperature sensor.
Because of its nature, you can connect multiple sensors to the same pin.
OneWire oneWire(tempSensorPin);
DallasTemperature sensors(&oneWire);
The setup function defines the spark variables to read temperatures in both Fahrenheit
and Celsius, which means we can display both on the Web. We must also call
sensors.begin() to start the monitoring process. The loop function is used to request the
reading and convert the values using some basic mathematics into our desired temperature
readings. The first thing that we call is sensors.requestTemperatures(), which gets the
reading from the temperature sensor. The second part accesses the reading itself using