//the three DS18B20 sensors has to be assigned to 3 addresses before
//connecting them to this project, otherwise, they read as one only!!!
//in real life, physical sensors may read different ID, not yet tested!!!
//as an alternative to assigning them, connect each sensor to a different
//bus as in the other project
//click on each sensor while in run mode, you will see different serial number
//1111..,2222..,3333..




//#include <OneWire.h>
#include <DallasTemperature.h>

// Connect DS18B29 to Arduino pin D12.
#define ONE_WIRE_BUS 12

// Setup a OneWire instance to communicate with any OneWire devices.
OneWire oneWire(ONE_WIRE_BUS);

// Pass our OneWire reference to Dallas Temperature sensor.
DallasTemperature sensors(&oneWire);

 byte numDevices = 0;

// Initialization of sensor and serial communication.
void setup()
{
  Serial.begin(115200);
  sensors.begin();

  byte address[8];

  while (oneWire.search(address))
  {
    Serial.print("Bus index=");
    Serial.print(numDevices);
    Serial.print(";  Device address=");
    for(byte i = 0; i < 8; i++)
    {
      Serial.print(address[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
    numDevices++;
  }
}

void loop()
{
  if (numDevices > 0)
  {
    sensors.requestTemperatures();

    for (byte i = 0; i < numDevices; i++)
    {
      float temperatureCelsius = sensors.getTempCByIndex(i);

      Serial.print("Bus index=");
      Serial.print(i);
      Serial.print(";  Temperature=");
      Serial.print(temperatureCelsius);
      Serial.println("°C");
    }
  }

  delay(4000);
}