/* DetentTest.ino - Detent Potentiometer Test Program */ // Set potentiometer wiper input pin number #define POT_PIN A0 unsigned long lastTime = 0; int potValue = 0; byte decValue = 0; byte lastDecValue = -1; int table [] = { 10, 80, 200, 300, 400, 600, 700, 800, 950, 1015 }; void setup () { Serial.begin(9600); Serial.println("Starting..."); pinMode(LED_BUILTIN, OUTPUT); pinMode(POT_PIN, INPUT); delay(10); } void loop() { unsigned long now = millis(); if (now - lastTime >= 100) { lastTime = now; decValue = readPot(); if (decValue != lastDecValue) { lastDecValue = decValue; Serial.print("Change: "); Serial.print(decValue); Serial.print(" - "); Serial.println(potValue); } digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN)); } } int readPot () { potValue = analogRead(POT_PIN); for (int n = 0; n < sizeof(table); n++) { if (potValue < table[n]) { return n; } } return sizeof(table); }