 unsigned int aTuneLookBack=20;
 
 boolean tuning = false;
+long now = millis();
 
 PID_ATune aTune(&Input, &Output);
+
+// ************************************************
+// States for state machine
+// ************************************************
+enum operatingState { OFF = 0, SETP, RUN, TUNE_P, TUNE_I, TUNE_D, AUTO};
+operatingState opState = OFF;
 
 void setup(void) {
   Setpoint = 55;

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

// 10 second Time Proportional Output window
int WindowSize = 10000; 
unsigned long windowStartTime;

// ************************************************

  Serial.println("starting program");
  
   // Start up the DS18B20 One Wire Temperature Sensor
  
   sensors.begin();
   if (!sensors.getAddress(tempSensor, 0)) 
   {
