Lessons and the learning game

Build carnival games

Touch targets, light gates and a big display on an Uno: whack-a-target, ring toss and a skee-ball booth with a high score and tickets.

What you build

One booth, three games. The same three light gates are the pegs of a ring toss and the holes of a skee-ball lane, the way a real booth reuses its sensors, and the finished booth runs itself from attract mode to the last ticket.

How it works

Touch is capacitance. A TTP223 feels the tiny change a finger makes near its pad, even through thin plastic, and drives SIG HIGH. Like the real chip, it takes about 60 ms to answer and ignores the pad for half a second after power-up.

Blocked is HIGH. Each light gate shines infrared across a slot. Anything in the slot cuts the beam and the pull-up takes S HIGH.

Edges catch fast balls. A skee-ball ball cuts a beam for a few milliseconds. The loop never waits, so it sees the moment each beam is cut.

Dwell time tells a ringer from a bounce. A ring counts only once its peg's beam has stayed cut for 300 ms. A ring that clips the peg and bounces away cuts it for less.

A high score that survives the night. The best score lives in the Uno's EEPROM, read at power-up and written only when it is beaten, because each cell wears out after about 100,000 writes. An erased chip reads 0xFFFF, which means no high score yet.

Tickets are a table. One ticket for every 30 points in whole-number division, and a jackpot of 20 more at 400 or over. The machine counts them out one chirp every 150 ms.

The course

Build carnival games gets there in six lessons, all on the same wiring with a new sketch each time:

  1. Whack targets: touch sensors, random pops, hits, misses and a time limit.
  2. Ring toss sensors: a gate at each peg, ringers, bounces and a turn.
  3. Skee-ball lanes: holes worth 10, 30 and 50, fast balls and the scoreboard.
  4. Scores: a high score kept in EEPROM.
  5. Tickets: a ticket table, a jackpot and a ticket machine.
  6. Project: a game booth: attract mode, a 30 second clock and the whole booth.

Every step is checked against the running circuit, apart from the last, where you make the booth your own and share it.