potentiometre-souris.ino
The potentiometer offset from its rest position becomes pointer speed: the board turns trackball. Calibration happens at boot — center the potentiometer before powering up.
Hardware required
An Arduino Leonardo (ATmega32U4, 16 MHz, 5 V) with native USB: the board can pose as a keyboard or a mouse. 1 10 kΩ potentiometer.
Wiring
Ends to 5 V/GND, wiper to A0.
How it works
A ±30 dead zone prevents drift; speed is capped at ±10 px per 20 ms step. In the Arduino IDE, select « Arduino Leonardo » and the port, then Upload. Caution: a sketch that sleeps too fast can « lose » the USB port; hold RESET for 12 s to wipe the bootloader.
Going further
A second potentiometer on A1 adds the Y axis for a 2-axis pointer.
potentiometre-souris.ino
// Potentiometre sur A0 : ecart au centre = vitesse du curseur.
#include <Mouse.h>
const int POT = A0;
int centre = 0;
void setup() {
Serial.begin(9600);
Mouse.begin();
centre = analogRead(POT); // position au demarrage = repos
Serial.print(F("Centre: "));
Serial.println(centre);
}
void loop() {
int v = analogRead(POT);
int ecart = v - centre;
if (abs(ecart) > 30) {
Mouse.move(constrain(ecart / 20, -10, 10), 0);
}
delay(20);
}