Introduction: Micro:bit Memory Game

A simple memory game, where you have to remember a sequence and answer if the second time around, the sequence was the exact same. Each round an additional step gets added to the sequence.

Step 1: Connect Your Micro:bit to a Computer

There are only two thing we need in order to make this memory game:

a micro:bit

a computer for the coding

If you do not have a micro:bit yet, get one ! They are incredibily fun little things to work with, and an easy way for kids to discover technology and programming.

In order to make our litle game, you must connect your micro:bit to a computer via the usb-cable.

Step 2: Go to the Micro:bit Python Editor

To create the game, we will need to put some code on our micro bit.
In order to do this, go to : https://python-editor-1-1-3.microbit.org/#

Select the basic code that is given, and paste the code below to the editor :

# Add your Python code here. E.g.
from microbit import * import random # generate displays actions = ["A", "B", Image.ARROW_N, Image.ARROW_E, Image.ARROW_S, Image.ARROW_W] # general game settings moves = [] gameover = False def show_moves(): display.show(moves, delay=1000) sleep(1000) display.show('=') sleep(1000) choices = (random.randint(1,2)) if choices == 2: display.show(moves, delay=1000) sleep(1000) elif choices == 1: length = len(moves)-1 newMoves = list(moves) newnr = (random.randint(0,length)) oldmove = newMoves[newnr] newmove = random.choice(actions) newMoves[newnr] = newmove if oldmove == newmove: choices = 2 display.show(newMoves, delay=1000) sleep(1000) buttonpressed = False while buttonpressed == False: display.show('?') if choices == 2: if button_b.was_pressed(): return True buttonpressed = True break elif button_a.was_pressed(): display.show(Image.HAPPY) sleep(2000) buttonpressed = True return False elif choices == 1: if button_a.was_pressed(): return True buttonpressed = True break elif button_b.was_pressed(): display.show(Image.HAPPY) sleep(2000) buttonpressed = True return False def add_nextMove(): moves.append(random.choice(actions)) # game while gameover == False: add_nextMove() gameover = show_moves() display.scroll("Missed.. ") display.show(Image.SAD) sleep(2000)

Step 3: Upload the Code to Your Micro:bit

First of all, be sure your microbit is connected to your computer.

In the editor, click Download in the upper left corner, to download the code to your computer, and drag and drop the file in file explorer to your microbit.

The orange light on the back of your micro:bit will start flashing.
As soon as the transfer is done, the code will start running and the first stage of the game will begin !

Step 4: Play !

To restart the game, press the button next to the usb-port on your micro:bit, which acts as a reset button.

You will see a symbol, followed by a '='-sign, a second symbol and a question mark.
By example : A = A ?

The game is simple: does the first sequence equal the second?

Do you think it does? Press A.
Do you think it doesn't? Press B.

If you're lucky, a smiley-face will appear, and you will go to the next round, adding a symbol to the sequence.

If you're out of luck, a sad face will appear.

Just try again by pressing the reset button on the back!

Enjoy !