Sim racing and flight sim controllers
Template a button box, a shifter with a handbrake or a flight panel on a Pro Micro, and test the code before you buy parts.
The three templates
Each is a built-in project on a Pro Micro, with every input it reads on the canvas and a config block at the top of its sketch:
- Sim racing button box: two encoders with push, an ignition key with an interlocked START, toggles for lights, wipers and the pit limiter, four buttons and three status LEDs.
- H-pattern shifter and handbrake: a gate pot and a throw pot read as six gears and reverse, two microswitches as sequential paddles, a hall sensor as the handbrake, and the gear on a four-digit display.
- Autopilot and landing gear panel: one knob for heading, altitude and vertical speed, an AP button with its light, and a gear lever with three green lights and a red one in transit.
Open them from /templates, or start the course on /learn: Sim racing and flight sim controllers.
What the PC would see
The sketches use the Arduino Joystick library's API (Joystick.h), so on a
real Pro Micro, Leonardo or Micro the board is a USB game controller. Mokxi
does not simulate that USB link. Each report is printed to the Serial Monitor
instead, one line per change:
[Joystick] buttons 0 3 | z 512
Buttons are numbered from 0 there, as the library numbers them. Windows and most games number them from 1, so button 0 is "Button 1" in a game's controls menu.
Changing the box
The button box sketch describes the panel in two tables, SWITCHES and
KNOBS. Add a row to add a switch: its pin, its kind and its button.
MOMENTARY: held while the button is held.PULSE: a toggle that sends one short press on every flip.PULSE_BOTH: a toggle that sends one button going on and another going off.HOLD: a toggle that holds its button while it is on.IGNITIONandSTARTER: a key switch, and a button that only works with the key on.
PULSE_MS and GAP_MS set how long a pulse is held and the gap before the
next one. Each encoder click is one pulse, and fast spins are queued so the
game sees every click.
Stand-ins
Mokxi has no toggle, key or guarded switch part, so slide switches stand in for all three: each is a contact that stays where it is put. A slide switch is on when its knob is over the leg wired to GND. The handbrake's magnet is dragged toward the 49E sensor.
Displays and lights on a real rig
A flight panel's numbers and an LED that shows what the car is doing both come from the game on a real rig, through tools such as MobiFlight, SimConnect, DCS-BIOS or SimHub talking to the board over USB. The templates keep their own count and light their LEDs from their own switches, and say so in the sketch.