// Workbench — detached positional servo controlled by a 10k potentiometer. // UNO R3: A0 = wiper, D9 = servo signal. See tutorial for separate power. #include Servo joint; const byte SERVO_PIN = 9; const byte KNOB_PIN = A0; const int MIN_US = 1400; // Deliberately narrow starting window; check exact servo. const int MAX_US = 1600; const unsigned long SAMPLE_MS = 20UL; unsigned long lastSampleAt = 0; int commandUs = 1500; void setup() { joint.attach(SERVO_PIN); joint.writeMicroseconds(commandUs); } void loop() { const unsigned long now = millis(); if (now - lastSampleAt < SAMPLE_MS) return; lastSampleAt = now; const int raw = constrain(analogRead(KNOB_PIN), 0, 1023); const int targetUs = map(raw, 0, 1023, MIN_US, MAX_US); // A small deadband avoids repeatedly changing almost identical commands. if (abs(targetUs - commandUs) >= 4) { commandUs = targetUs; joint.writeMicroseconds(commandUs); } }