Handheld console

A games cabinet in one body: a 128x64 OLED above a D-pad, A, B, Start and Select, with a twelve-pin header along the bottom.

There is nothing new inside it. The screen is the same SSD1306 this library already models, on the same two-wire bus at the same address, and the eight buttons are eight momentary contacts to the cabinet's own ground. A sketch that already drives an OLED and reads buttons with INPUT_PULLUP drives this one with no new protocol and no new library, which is the point of putting them in one case.

Pins

Pin What it does
VCC, GND The supply. GND is the panel's ground and the common return of all eight buttons.
SCL, SDA The panel's I2C bus. The module carries the pull-ups.
UP, DOWN, LEFT, RIGHT The molded D-pad; each shorts to GND when pressed.
A, B, START, SELECT The four buttons, the same way.

Properties

address: the panel's 7-bit I2C address, 60 (0x3C) by default.

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

While it runs

Click and hold any of the eight buttons.

Click the cabinet and it takes your keyboard: the arrow keys are the D-pad, Z is A, X is B, Enter is Start and Shift is Select. Escape hands the keyboard back to the canvas.

What the model gets right

The panel is the SSD1306 model itself, not a copy of it: the same I2C slave, the same command set, the same 1 KB of display RAM, the same addressing modes and the same pixels on the frame channel.

A pressed button is a real low-resistance contact from its own pin to whatever GND is sitting on; released, the pin is high impedance and whatever pull-up the board provides decides the level. rocker models the molded plastic a real D-pad has: of two opposed directions, the one that arrived later wins, which is what a one-piece rocker does mechanically and what stops a keyboard's held arrow keys from asking for a state no hardware could make.

What it does not model

No contact bounce: a molded pad's carbon pills make far more quietly than a tactile switch, so the pushbutton is the part to reach for when bounce is the lesson.

No speaker, no battery gauge and no backlight. This cabinet is a panel and eight switches, and it says so.

GND is presented as a load and is never driven, because it is the panel's ground as well as the buttons' common. Leave it unwired and the buttons do nothing, which is what an unsoldered ground wire does to a real one.

Common mistakes

Wiring the buttons with external pull-down resistors and expecting a press to read HIGH. Every contact here goes to ground, so a pressed button reads LOW and the pull-up belongs inside the chip: pinMode(pin, INPUT_PULLUP).

Forgetting that the probe is the buttons, not the glass. The screen travels on the frame channel the way every display in the library does; the probe is the eight-bit mask of what is held.

See it in action

Console runs Snake and Breakout on it, with a menu on the D-pad. Open it at /templates.