SUPER PROMPT FOR QWEN3.6-PLUS Act as an expert embedded systems engineer. Generate a complete, production-ready Arduino sketch for a closed-loop DC motor speed controller using the following exact specifications: 🔹 HARDWARE SETUP - MCU: Seeed Studio XIAO ESP32-C3 - Encoder: OSEPP DC Motor Encoder (Channel A only) - Motor Driver: 2-pin DC driver (PWM input + Direction input) - Potentiometer: 10kΩ linear, used for target speed input - Display: 0.91" I2C OLED (128x32 SSD1306) 🔹 PIN MAPPING (XIAO Dx Aliases) - Encoder A → D1 (GPIO3, interrupt-capable) - Motor PWM → D2 (GPIO4) - Motor DIR → D3 (GPIO6) - Pot Wiper → D0 (GPIO2, ADC-capable) - OLED SDA → D4 (GPIO5) - OLED SCL → D5 (GPIO7) ⚠️ CRITICAL: All logic components (Encoder, Pot) MUST be powered at 3.3V. ESP32-C3 GPIO pins are NOT 5V tolerant. 🔹 CODE REQUIREMENTS 1. Libraries: `Wire.h`, `Adafruit_GFX.h`, `Adafruit_SSD1306.h` 2. Force 12-bit ADC: `analogReadResolution(12)` 3. Explicit I2C init: `Wire.begin(OLED_SDA, OLED_SCL)` 4. Encoder: Interrupt-driven on rising edge with `micros()` debounce (≥800µs) 5. Speed Calc: 250ms sampling window, convert pulses → RPM → BPM. Apply exponential smoothing (0.8/0.2) 6. PID Control: - Default gains: KP=1.5, KI=0.8, KD=0.1 - Anti-windup: ±500 - Reset integral when target < 1.0 BPM - Scale KI/KD to time units 7. Motor Driver Logic: - Inverted PWM: 0 = full speed, 255 = stop (hardcoded `INVERT_PWM = true`) - Active braking: Pull DIR LOW when target = 0 8. OLED UI (128x32): - `setTextSize(1)`, integer values only - Line 1 (y=0): "TGT: XX BPM" - Line 2 (y=11): "ACT: XX BPM" - Line 3 (y=22): "PWR: XX%" 9. Serial Debug: Print every 500ms: Pot raw, Target BPM, Actual BPM, PWM% 🔹 DELIVERABLES 1. Complete, ready-to-upload Arduino sketch matching all specs 2. Concise calibration & troubleshooting checklist covering: - How to verify `PULSES_PER_REV` - PID tuning steps - Noise mitigation (0.1µF cap placement) - Driver logic inversion fallback - 3.3V vs 5V wiring warning Ensure code is heavily commented, uses non-blocking timing, and compiles cleanly on ESP32 Arduino Core 3.0+.