Gamepad (six-button pad)

A six-button console-style pad: a four-way D-pad plus A and B, each switch to ground on its own pin.

Electrically a games controller like this is six momentary contacts with one leg of each tied to a common ground. There is no chip, no shift register and no serial protocol on the board, which is why every sketch reads it with INPUT_PULLUP.

Pins

Pin What it does
UP, DOWN, LEFT, RIGHT, A, B Each shorts to GND when pressed.
GND The common return.

Properties

rocker: on by default: models the plastic rocker that makes opposite directions mechanically impossible.

While it runs

Click a direction or a button, or use the arrow keys plus Z and X on the keyboard.

What the model gets right

A pressed button is a real low-resistance contact to GND; released, the pin is high impedance and whatever pull-up the board provides decides the level. rocker models the molded plastic rocker a real D-pad has: on by default, it drops the older of two opposed directions the instant the second one arrives, which is what a one-piece rocker does mechanically and what stops a keyboard's held arrow keys from producing a state no hardware could ever make.

What it does not model

No contact bounce. A molded pad's carbon-pill contacts make far more quietly than a tactile switch does, so this part does not chatter; the pushbutton is the part to reach for when bounce is the lesson. "Far more quietly" is not "silently", though: a real pad does chatter for a fraction of a millisecond and this one never does at all.

rocker is a rule rather than a mechanism: it drops the older of two opposed directions the instant the second arrives. A real rocker cannot be pressed on two opposite sides at once at all, and on the way between two directions it passes through a moment with neither made; neither of those is modeled. There is no diagonal restriction either, so up and left together are allowed, as they are on a real pad.

Common mistakes

Turning rocker off and then wiring a sketch that assumes opposite directions can never both read pressed at once. With rocker off, that assumption is no longer true, which is exactly the point of the property.

See it in action

D-pad pong uses all six buttons for a two-paddle game. Open it at /templates.