 
 // Timing
 long previousMillis = 0;
-long tempInterval = 2000;
+long tempInterval = 1000;
+
+// PID
+double setpoint = 95;
+double input = 0;
+double oldInput = 0;
+double output;
+int windowSize = 5000;
+unsigned long windowStartTime;
 
 // Defaults
 int displayMode = 0;
 float temp = 0;
 float oldTemp = 0;
-boolean relayStatus = false;
+boolean relayStatus = true;
 boolean oldRelayStatus = false;
 boolean refreshDisplay = true;
 

//--> Arduino Main Loop <--

void loop(void){
  unsigned long currentMillis = millis();
  
  // Is it time to check the temp?
  if(currentMillis - previousMillis > tempInterval) {
    previousMillis = currentMillis;
    
    temp = checkTemp();
    relayStatus = controlRelay(temp, desiredTemp);
    
    if (temp != oldTemp){
      refreshDisplay = true;
      oldTemp = temp;
    }
    else if (relayStatus != oldRelayStatus){
      refreshDisplay = true;
      oldRelayStatus = relayStatus;
    }
  }
  
  if (refreshDisplay == true){
    printDisplay(displayMode);
  }
}


// Initialize LCD display
LiquidCrystal lcd(5, 4, 0, 1, 2, 3);

// Setup PID
#define RelayPin 11
PID myPID(&input, &output, &setpoint,1600,8,0, DIRECT);


//--> Arduino Setup <--

void setup(void)
{
  // Setup the LCD
  lcd.begin(16, 2);
  lcd.createChar(1, on);
  lcd.createChar(2, off);
  // Print startup message to LCD
  lcd.clear();
  lcd.print("-= Brewtus II =-");

  // start serial port
  Serial.begin(9600);

  // Setup relay pin
  pinMode(relayPin, OUTPUT);

  // Start up the sensors library
  sensors.begin();
  // set the resolution to 10 bit
  sensors.setResolution(tempProbe, 12);

  // Setup PID
  windowStartTime = millis();
  myPID.SetOutputLimits(0, windowSize);
  myPID.SetMode(AUTOMATIC);

  // Add a delay to show the "boot screen"
  delay(2000);
}


