Trim wheel 🎛️ TrimWheel WIP

STM32C++ / ArduinoServo PWMRotary Encoder

What is it?

TrimWheel is an Arduino sketch that reads a quadrature rotary encoder and drives a standard hobby servo. The code uses ENCODER_PIN_A (PB8) and ENCODER_PIN_B (PB7) to read encoder states and reports rotation direction over Serial (9600 baud) as "Clockwise" or "Counterclockwise". A servo is attached to SERVO_PIN (PB9) via the Servo library; on startup the sketch writes a default microsecond pulse (500) to the servo.

The sketch also accepts newline-terminated serial commands of the form Servo:NN where NN is a number 0–100. The command is parsed as a float, divided by 4 in the sketch, then mapped to a pulse width in microseconds between 500 and 2500 before being written to the servo. After changing the servo the sketch echoes the (post-division) value back over Serial.

Notes: encoder state changes are detected by reading both A/B pins and comparing transitions; serial input is read with readStringUntil('\n') and trimmed before parsing. The code therefore exposes both rotation events (as direction strings) and a simple serial interface to set the servo position.

View Source on GitLab ← Back to Kirisoft