 
 //Parts of code taken from http://playground.arduino.cc/Main/RotaryEncoders J.Carter(of Earth)
 
-// 'threshold' is the De-bounce Adjustment factor for the Rotary Encoder. 
-//
-// The threshold value I'm using limits it to 100 half pulses a second
-//
-// My encoder has 12 pulses per 360deg rotation and the specs say
-// it is rated at a maximum of 100rpm.
-//
-// This threshold will permit my encoder to reach 250rpm so if it was connected
-// to a motor instead of a manually operated knob I
-// might possibly need to adjust it to 25000. However, this threshold
-// value is working perfectly for my situation
-//
+// 'threshold' is the De-bounce Adjustment factor for the Rotary Encoder. halfSteps
 volatile unsigned long threshold = 1000;
 
-// 'rotaryHalfSteps' is the counter of half-steps. The actual
-// number of steps will be equal to rotaryHalfSteps / 2
+// 'halfStepshalfSteps' is the counter of half-steps. The actual
+// number of steps will be equal to halfSteps / 2
 //
-volatile long rotaryHalfSteps = 0;
+volatile long halfSteps = 0;
+long halfStepsCorrection = 0;
 
 // Working variables for the interrupt routines
 //

  pinMode(pinReset, INPUT);
  digitalWrite(pinReset, HIGH);
  PCintPort::attachInterrupt(pinReset, &reset, CHANGE);
  Serial.begin(115200);
  Serial.println("---------------------------------------");
}

uint8_t i;

void loop() {
  long actualRotaryTicks = (rotaryHalfSteps / 2);
    // read the analog in value:
  Serial.print(rotaryHalfSteps*8+512); 
  Serial.print(",");  
  //Serial.print("\t output = ");      
  //Serial.println(outputValue);
  delay(2);
    
  for (int thisPin = 1; thisPin < 6; thisPin++) {
  sensorValue = analogRead(thisPin);            
  
  // print the results to the serial monitor:

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 analogInPin = 0;  // Analog input pin that the potentiometer is attached to
