Part

Game console buttons

A D-pad plus A and B, six switches to ground. Click them, or use the arrow keys, Z and X.

See every part
  • 7 pins
  • 1 setting
  • In 5 projects
  • In 3 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Game console buttons in brief

What it is, and every setting the properties panel gives it.

The gamepad is a six-button console-style pad, a four-way D-pad plus A and B, with every button a contact to a shared ground and no chip, shift register or serial protocol on the board. Its pins are UP, DOWN, LEFT, RIGHT, A, B and GND, and no supply. On an Uno each button goes to its own digital pin with INPUT_PULLUP and reads LOW when pressed; an ESP32 wires it the same way on any six GPIOs. Mokxi models a pressed button as a low-resistance contact to GND and a released one as an open pin. The rocker property, on by default, drops the older of two opposed directions the moment the second arrives, as a one-piece rocker does, so held arrow keys can never read up and down at once; diagonals stay allowed. Click the buttons, or use the arrow keys with Z and X. The mokxi_gamepad.h driver adds an 8 millisecond settle and gives held(), pressed(), dx() and dy(). The classic mistake is forgetting the pull-ups, which leaves released buttons floating. Contact bounce, which a real carbon-pill pad has for a fraction of a millisecond, is not modeled.

Family
Inputs
Pins
7
rocker
true
on by default: models the plastic rocker that makes opposite directions mechanically impossible.
Pins

7 pins

Named as the editor names them, so a wire lands where you expect it.

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

How to use a six-button gamepad with an Arduino

Each button is a contact to the shared GND, so wire GND to ground and the six buttons to six digital pins with their pull-ups on. In D-pad pong, UP is pin 7, DOWN 8, LEFT 5, RIGHT 4, A 3 and B 2. Click the pad or use the arrow keys with Z and X.

The mokxi_gamepad.h driver sets the pull-ups in begin() and, called once a frame, update() lets a change through after 8 ms. held() says a button is down, pressed() that it went down since the last update, and dx() gives -1, 0 or 1 from the D-pad. The pad’s rocker property stops up and down, or left and right, reading pressed at once.

Part pin
Board pin
UP
Pin 7
DOWN
Pin 8
LEFT
Pin 5
RIGHT
Pin 4
A
Pin 3
B
Pin 2
GND
GND

mokxi_gamepad.h works the same on an ESP32: the pad has no supply pin, only contacts to ground.

Arduino Uno: D-pad ponglive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Reading the pad, from D-pad pong
//        up  down left right  A  B
Gamepad pad(7, 8, 5, 4, 3, 2);

void setup() {
  pad.begin();
}

void loop() {
  pad.update();
  if (pad.pressed(PAD_A)) serve();
  int8_t dir = pad.dx();
}
How it is modeled

What is true about the Game console buttons, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

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.

Not modeled

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.

From Gamepad (six-button pad), in full.

Projects

See the Game console buttons in a project

5 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

Each of these 3 boards has a built-in project with the Game console buttons in it.

Wire up the Game console buttons

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.