/********************************************************************/
// First we include the libraries
#include <OneWire.h> 
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 2 
/********************************************************************/
// 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. 
DallasTemperature sensors(&oneWire);
/********************************************************************/ 
void setup(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensors.begin(); 
} 
void loop(void) 
{ 
 // call sensors.requestTemperatures() to issue a global temperature 
 // request to all devices on the bus 
/********************************************************************/
// Serial.print(" Requesting temperatures..."); 
 sensors.requestTemperatures(); // Send the command to get temperature readings 
// Serial.println("DONE"); 
/********************************************************************/
 Serial.print("T 1:..... "); 
 Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"?  
 
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
  
  Serial.print("T 2:..... "); 
 Serial.println(sensors.getTempCByIndex(1));
  Serial.print("T 3:..... "); 
 Serial.println(sensors.getTempCByIndex(2));
  Serial.print("T 4:..... "); 
 Serial.println(sensors.getTempCByIndex(3));
  Serial.print("T 5:..... "); 
 Serial.println(sensors.getTempCByIndex(4));
  Serial.print("T 6:..... "); 
 Serial.println(sensors.getTempCByIndex(5));
   Serial.print("T 7:..... "); 
 Serial.println(sensors.getTempCByIndex(6));
   Serial.print("T 8:..... "); 
 Serial.println(sensors.getTempCByIndex(7));

   Serial.println(".........................");

  float T1=sensors.getTempCByIndex(0);
 float T2=sensors.getTempCByIndex(1);
 float T3=sensors.getTempCByIndex(2);
 float T4=sensors.getTempCByIndex(3);
 float T5=sensors.getTempCByIndex(4);
   float T6=sensors.getTempCByIndex(5);
    float T7=sensors.getTempCByIndex(6);
     float T8=sensors.getTempCByIndex(7);
     float Tsred= ((T1+T2+T3+T4+T5+T6+T7+T8)/8);
  Serial.println(" ");
    Serial.print("T średnia:....    ");
    Serial.println(Tsred);
   delay(7000); 
} 
