Just wondering... How does the program assign the sensor's index in sensor.getTempCByIndex()?
I will be using this code:
// Load Libraries for DS1820 and OneWire
#include <OneWire.h>
#include <DallasTemperature.h>
// Variables for temperature readings
float tempOne;
float tempTwo;
// DS1820 Data wire is plugged into pin 4 on the Arduino
#define ONE_WIRE_BUS 3
// Setup oneWire instance to communicate with devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup()
{
Serial.begin(9600);
// Start the OneWire library
sensors.begin();
}
void loop()
{
// Read the temperature
readtemp();
// Write the Results to the serial Monitor
serialPrint();
}
void readtemp()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
tempOne = (sensors.getTempCByIndex(0));
tempTwo = (sensors.getTempCByIndex(1));
}
void serialPrint()
{
Serial.print("Sensor1: ");
Serial.print(tempOne);
Serial.print("C");
Serial.print(" Sensor2: ");
Serial.print(tempTwo);
Serial.println("C");
delay (500);
}
How will I know which sensor will be assigned to 0 and 1?
Will it be based on its address? or just whatever I connected first?