Build a slot machine

A three-reel slot machine on an Uno with a real arcade lever, and the honest math behind its odds.

The finished machine

Slot machine has everything a cabinet needs:

  • The lever: an arcade lever. Only its DOWN switch is wired, because pulling it toward you is the whole game.
  • Three reels: three 128x64 OLEDs. Each spins, then they stop one at a time, left to right.
  • COIN, BET- and BET+: arcade buttons. A coin is five credits, and the bet goes from 1 to 3.
  • Win lights and sound: eight WS2812 LEDs and a piezo.

Every OLED answers at address 0x3C, and a module can only be moved to 0x3D, so three cannot share one I2C bus. Each screen gets two wires of its own (A0 and A1, A2 and A3, A4 and A5) and the sketch talks I2C by hand. It also keeps no frame buffer: a 128x64 frame is 1 KB and the Uno has 2 KB, so each reel is worked out pixel by pixel and sent straight to the glass.

The odds

Every reel carries the same strip of sixteen stops:

Symbol Stops
Cherry 4
Lemon 6
Bell 3
Bar 2
Seven 1

Each spin picks one stop on each reel, all sixteen equally likely, so there are 16 x 16 x 16 = 4,096 outcomes and every one is as likely as any other. The table pays, per credit bet:

Line Pays Ways out of 4,096
7 7 7 100 1
Bar Bar Bar 40 8
Bell Bell Bell 15 27
Cherry Cherry Cherry 10 64
Lemon Lemon Lemon 5 216
Cherry Cherry, then anything else 3 192
Cherry on the first reel only 1 768

Multiply each payout by its ways and add them up: 3,889 credits back for every 4,096 bet, or 94.9 percent. That is the return to player. 1,276 of the 4,096 outcomes pay something, a little under one spin in three, but 768 of those only hand your bet back. 508 pay more than you bet.

So over a long run the machine keeps about 5 credits of every 100. Any one session can go either way, and the jackpot comes up once in 4,096 spins on average. Every slot machine is built on a table like this one. This one shows you the table.

The reels' stops are chosen the instant you pull, and the spin is only theater. An Uno has no true randomness either, so each coin seeds the random numbers from the microsecond it was pressed.

The course

Build a slot machine gets there in four lessons, each on the same layout with more of the parts in place:

  1. The lever: one switch, read once per pull.
  2. One reel: a spinning reel drawn without a frame buffer.
  3. Three reels: three buses, and reels that stop one by one.
  4. The whole machine: credits, bets, the pay table, lights and sound.

Every step is checked against the running circuit.