   return (float) raw / 16.0;
 }
 
-void loop(void) {
+float getTemp() {
   byte i;
   byte present = 0;
   byte data[12];
   byte addr[8];
-  float celsius;
-  double ratio;
+  unsigned long startTime;
   
   ds.reset_search();
   if ( !ds.search(addr)) {
     Serial.println("No more addresses.");
     Serial.println();
     ds.reset_search();
-    delay(3000);
-    return;
+    startTime = millis();
+    while(millis() - startTime < 3000);
+    return -1000;
   }
 
   Serial.print("ROM =");


  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }

  // the first ROM byte indicates which chip
  int type_s = getChipType(addr[0]);

  if(!ds.reset()) {
    Serial.println("Failed to reset");
    return;
  }
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(DELAY);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();

  Serial.print("Runtime: ");
  Serial.println(PID_interval * ratio);

  Serial.println("LOW");
  digitalWrite(RELAY_PIN, LOW);
  while(millis() - windowStartTime < PID_interval * ratio);
  
  Serial.println("HIGH");
  digitalWrite(RELAY_PIN, HIGH);
