Simon Memory Game

On an Arduino Nano 33 BLE, build the classic Simon game: a colour sequence that grows by one random colour per round, played back on three LEDs with exact timing, checked against debounced button presses, with a timeout and a score.

Board
Nano 33 BLE · Arduino
Schwierigkeit
Schwer
Thema
Data Handling & Algorithms
Zugang
Kostenlos

Die Aufgabe

Simon Memory Game

The classic memory toy: the game flashes a sequence of colours, and the player repeats it on the buttons. Every round the sequence gets one colour longer. One mistake, or too long a pause, and the game is over.

Hardware

  • Arduino Nano 33 BLE (nRF52840, 3.3 V logic). Serial console on Serial1 (D0/D1), 115200 baud. Serial is USB and is not seen by the tests.
  • LEDs with series resistors to GND, HIGH = on: D2 red, D3 green, D4 blue.
  • Buttons to GND (use the internal pull-ups, LOW = pressed): D8 red, D9 green, D10 blue.

Requirements

Write the sketch in sketch/sketch.ino (setup() and loop()). Colours are numbered 0 = red, 1 = green, 2 = blue (the pin tables are in the starter file).

  1. Start-up. Open Serial1 at 115200 baud, LEDs off, buttons with pull-ups, print READY, and start a game.
  2. Rounds. A game starts with an empty sequence. Each round begins 500 ms after the previous round ended (or after the game started): add one random colour to the end of the sequence (the earlier colours stay the same) and print PLAY <n>, where <n> is the sequence length.
  3. Playback. Starting at the PLAY line, show the sequence: colour k (from 0) is on from 600k ms to 600k + 400 ms, with only that colour's LED lit, and all LEDs off in between. Right after the last flash's 200 ms gap, print YOUR TURN.
  4. Player's turn. A press counts after 20 ms of steady LOW (bounce is ignored). Each press must match the next colour of the sequence.
    • All colours right: print ROUND <n> OK and start the next round (500 ms later).
    • A wrong colour: print GAME OVER <score>, where the score is the number of rounds completed (a mistake in round 4 scores 3).
    • No press for 3000 ms (since YOUR TURN or the last press): game over in the same way.
  5. New game. 2000 ms after a game over, start a new game (round 1 again).
  6. Never block with delay().

Example console output:

READY
PLAY 1
YOUR TURN
ROUND 1 OK
PLAY 2
YOUR TURN
GAME OVER 1
PLAY 1
Playback without delay()

Remember when the playback started. With t = millis() - start, the flash number is t / 600 and the LED is on while t % 600 < 400. When the flash number reaches the sequence length, playback is done.

Wiring

Build the circuit in the Wiring tab: the three LEDs with their series resistors on D2, D3, D4, and the three buttons between D8 / D9 / D10 and GND.

Success criteria

  1. The sketch builds.
  2. Each round replays the whole sequence (one colour longer than before) with exactly 400 ms on / 200 ms off per colour.
  3. Correct answers pass the round; a wrong colour or a 3 s pause ends the game with the number of completed rounds.
  4. A new game starts 2 s after a game over, and bouncing buttons count once.

Was du bekommst

  • Deine Firmware wird auf einem emulierten Board gebaut, ausgeführt und durch Hardware-Tests geprüft.
  • Kein Entwicklungsboard und keine lokale Toolchain nötig.

Neu bei Embedded? Starte mit der Roadmap: Embedded-Systeme lernen (Englisch)