Source: https://mokxi.com/learn/socd-cleaning-explained
Updated: 2026-10-05

Learn

# SOCD cleaning explained

Intermediate

Written by the Mokxi team, updated October 5, 2026

Start building free Open the editor

Or see every lesson.

- 261 parts on the bench
- 31 boards running now
- 1.00x real time, on every board

Press Run, then hold left and right together

Hold two opposite arrow keys and read the Serial Monitor. Click the slide switch to change the rule.

SOCD stands for Simultaneous Opposing Cardinal Directions: left and right held at the same time, or up and down. On a joystick lever it cannot happen, because the gate stops the stick going two ways at once. On a keyboard or an all-button controller it happens all the time, because the directions are separate keys.

A game has no sensible meaning for left and right at once, so the controller’s firmware decides before it reports anything. That decision is SOCD cleaning. There are only a few rules in common use, each is a few lines of code, and the circuit above lets you try two of them and watch the result.

Press Run and hold two opposite arrow keys. The Serial Monitor shows what was held and the direction that came out, in numpad notation where 5 is neutral, 4 is left and 6 is right. The four LEDs show the same cleaned direction. The slide switch changes the rule.

## The common rules

Neutral: both opposite directions together give neither. Left plus right is neutral, and up plus down is neutral. It is the simplest rule and it never produces a direction you did not mean, but letting go of one side is needed before the other one registers again.

Last input wins: the direction pressed most recently takes over, and letting go of it brings back the one still held. Hold left, add right, and you get right; release right and you are back to left without pressing anything. This makes very quick changes of direction possible.

First input wins: the direction pressed first keeps priority, and the second one is ignored while both are held. In code it is the mirror of last input wins: a held direction keeps its place no matter what is added on the other side, until it is let go.

Up priority: left plus right is neutral, but up plus down gives up. Players use it to hold down and tap up for a jump without releasing down.

Off: both directions are reported and the game decides. GP2040-CE, a widely used open source gamepad firmware, offers all of these, and its documentation describes exactly what each does on each axis.

## Neutral in code

Treat each axis as a number: minus one, zero or plus one. For the horizontal axis, right is plus one and left is minus one, so the raw value is right minus left. When both are held, that sum is already zero, so neutral cleaning is what you get for free from the subtraction. The fight stick example relies on exactly that.

The direction in numpad notation is then 5 plus the horizontal axis plus three times the vertical one, with up as plus one. Neutral is 5, up-right is 9, down-left is 1.

Neutral and last input wins

## Last input wins in code

Last input wins needs one piece of memory per axis: which side went down most recently. The sketch keeps the previous reading of every direction and, when one goes from released to pressed, records its side. When both sides are held, the recorded side wins. When one is released, the plain subtraction takes over again and the other side comes back on its own.

Record the press on the edge, not on the level. If the code simply checked "is right held" first, right would always win and the rule would really be a fixed priority, not last input.

First input wins is the mirror image: record a side only when the other side is not already held. Up priority is a special case on the vertical axis: if both are held, return up.

## Why cleaning happens in the controller

If the controller reports both directions, each game handles it its own way, and some handle it badly. Cleaning in the firmware means the game only ever sees states a lever could make, or a defined rule, which is predictable for the player and for the game.

It also means the rule is part of your controller’s behavior, and some tournament rule sets and games say which rules a controller may use. If you build for competition, check the rules for the event and the game, and make the mode easy to switch, as the slide switch in the example does.

## What the simulator shows, and what it does not

Everything above runs on the simulated Pro Micro as a real sketch: the edges, the memory of the last press, the axis math and the LEDs. The console pad’s rocker is turned off, so its four buttons are independent switches, the way a leverless controller’s are.

What Mokxi does not simulate is a console or PC on the other end of the cable. A sketch that uses Joystick.h or Keyboard.h prints each report it would send to the Serial Monitor instead, so you can read exactly what the host would get. On a real board those reports go over USB, or you use gamepad firmware that already does the cleaning.

## Questions

What does SOCD stand for?

Simultaneous Opposing Cardinal Directions: left and right, or up and down, held at the same time.

What is the difference between neutral and last input wins?

With neutral, left plus right gives no direction. With last input wins, the direction pressed most recently wins, and releasing it brings back the other one if it is still held.

Does a joystick lever need SOCD cleaning?

A lever’s gate cannot press opposite directions together, so it rarely matters. It is cheap to add anyway, and neutral cleaning falls out of the axis math for free.

Which SOCD mode should I use?

It depends on the game and the rules of the events you enter. Make the mode switchable, and check the event rules before you compete.

Related

## Keep going

Design Your Own Fight Stick or Leverless Controller Leverless Controller Build: Buttons, Pins and Code DIY Fight Stick on an Arduino Pro Micro Interrupts vs Polling on Arduino, Side by Side Debouncing a Button: Why It Fires More Than Once The leverless SOCD project: code, parts and wiring Intermediate The fight stick project on a Pro Micro Intermediate The SparkFun Pro Micro in Mokxi The project page, with the full sketch Intermediate

Sources

## Where the facts on this page come from

- GP2040-CE hotkeys: up priority, neutral, last win, first win and off
- GP2040-CE settings: the default SOCD cleaning mode

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
