#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 25
// 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);
float Temp_T = 0;
float Temp_S = 0;
float oldTemp_T = 0;
float oldTemp_S = 0;
void setup() {
// Start up the onewire sensor library
Serial.begin(115200);
sensors.begin();
}
void loop() { //Choose Serial1 or Serial2 as required
Temperature();
}
void Temperature(){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Serial.println(sensors.getTempCByIndex(0));
//Serial.print("Temperature2: ");
//Serial.println(sensors.getTempCByIndex(1));
Temp_T = sensors.getTempCByIndex(0);
if (Temp_T != oldTemp_T )
{
oldTemp_T = Temp_T;
Serial.print("Temp_T: ");
Serial.println(Temp_T);
// tft.setCursor(404, 34);
//tft.setTextColor(0x57FF, 0xFAAA);
//tft.print(Temp_T);
}
Temp_S = sensors.getTempCByIndex(1);
if (Temp_S != oldTemp_S )
{
oldTemp_S = Temp_S;
Serial.print("Temp_S: ");
Serial.println(Temp_S);
// tft.setCursor(387, 141);
//tft.setTextColor(0x57FF, 0xFAAA);
//tft.print(Temp_S);
}
//delay(1000);
}