int potValue, oldPotValue, potPin = A0;
void setup() {
Serial.begin(115200);
Serial.println("Center potentiometer around 512.");
while (analogRead(potPin) < 500 || analogRead(potPin) > 524); // deadband start
}
void loop() {
potValue = analogRead(potPin); // read current pot value
if (oldPotValue != potValue) { // compare to stored pot value
if (oldPotValue > potValue) { // if old value is greater than new value
Serial.print(potValue);
Serial.println (" <-- CCW"); // pot was turned "left"
} else { // but if old value is less than new value
Serial.print("CW --> "); // pot was turned "right"
Serial.println(potValue);
}
oldPotValue = potValue; // store current pot value
}
}