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.
- Placa
- Nano 33 BLE · Arduino
- Dificultad
- Difícil
- Tema
- Data Handling & Algorithms
- Acceso
- Gratis
La tarea
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.Serialis 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).
- Start-up. Open
Serial1at 115200 baud, LEDs off, buttons with pull-ups, printREADY, and start a game. - 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. - Playback. Starting at the
PLAYline, 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, printYOUR TURN. - 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> OKand 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 TURNor the last press): game over in the same way.
- All colours right: print
- New game. 2000 ms after a game over, start a new game (round 1 again).
- 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
- The sketch builds.
- Each round replays the whole sequence (one colour longer than before) with exactly 400 ms on / 200 ms off per colour.
- Correct answers pass the round; a wrong colour or a 3 s pause ends the game with the number of completed rounds.
- A new game starts 2 s after a game over, and bouncing buttons count once.
Qué incluye
- Tu firmware se compila y ejecuta en una placa emulada y se comprueba con pruebas a nivel de hardware.
- No necesitas placa de desarrollo ni toolchain local.
¿Nuevo en embebidos? Empieza por la hoja de ruta: Cómo aprender sistemas embebidos (en inglés)