 //Specify the links and initial tuning parameters (Kp, Ki, Kd)
 PID myPID(&Input, &Output, &Setpoint, 1, 1, 1, DIRECT);
 
+
+//*****************************************************************************//
+// 'threshold' is the De-bounce Adjustment factor for the Rotary Encoder. halfSteps
+volatile unsigned long threshold = 1000;
+
+// 'halfSteps' is the counter of half-steps. The actual
+// number of steps will be equal to halfSteps / 2
+//
+volatile long halfSteps = 0;
+long halfStepsCorrection = 0;
+
+// Working variables for the interrupt routines
+//
+volatile unsigned long int0time = 0;
+volatile unsigned long int1time = 0;
+volatile uint8_t int0signal = 0;
+volatile uint8_t int1signal = 0;
+volatile uint8_t int0history = 0;
+volatile uint8_t int1history = 0;
+
+uint8_t latest_interrupted_pin;
+uint8_t interrupt_count[20]={0}; // 20 possible arduino pins
+
+int pinA = 2;
+int pinB = 3;
+int pinReset = 4;
+
+boolean isAbsoluteReference = false;
+
+// These constants won't change.  They're used to give names
+// to the pins used:
+const int potPin = 1;  // Analog input pin that the potentiometer is attached to
+
+int barrePotentiometerValue = 0;        // value read from the pot
+
+double linearResolution = 0.005; //Resolution of the linear encoder (in meters)
+double linearRange = 0.5; //Range of the sensor to normalize data (+/- linearRange/2)
+
+double potentiometerRangeDeg= 300; 
+double potentiometerMaxRange = potentiometerRangeDeg * 3.1414/180;
+double potentiometerUsedRange = 3.1415;
+double potentiometerDistance = 0.05;
+//*********************************************************************************************
+
 void setup()
 {
   // Initialize software serial communication with Sabertooth 

}




  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  myPID.SetOutputLimits(-50, 50);
  
  //*****************************************************
  pinMode(pinA, INPUT);
  digitalWrite(pinA, HIGH);
  attachInterrupt(0, int0, CHANGE);
  //PCintPort::attachInterrupt(pinA, &int0, CHANGE);
  pinMode(pinB, INPUT);
  digitalWrite(pinB, HIGH);
  attachInterrupt(1, int1, CHANGE);
  //PCintPort::attachInterrupt(pinB, &int1, CHANGE);
  
  // Pin used to get absolute position
  pinMode(pinReset, INPUT);
  digitalWrite(pinReset, HIGH);
  PCintPort::attachInterrupt(pinReset, &reset, CHANGE);
  
}

void serialEvent() {
