This section gets you up and running with the BBC microbit simulator.

Starting the simulator

We will use the micro:bit simulator, which can be found at the following URL

Microsoft MakeCode for micro:bit

Navigate to the makecode website and start a new project. Next, give your project a name and click the create button. This will start the simulator. At the top of the screen, switch the simulator to the python-mode by clicking python. See the screenshots below for more guidance.

Untitled

Untitled

Untitled

Using the simulator

If you follow the instructions above, you should see the following interface. The left side of the screen shows a simulated microbit board. You can interact with the board by clicking the buttons. If you are using any of the sensors, this area will show sliders that allow you to manipulate the input to the sensors.

Untitled

The left side of the screen is where you can write the code that will run on the simulated board. If you have real physical micro:bit board, you can download the code you write in this simulator and run it on the real board.

A nice feature of the simulator is that it provides an easy way to find the python code for a range of tasks you might want to complete. The menu provides snippets of code you can directly draw into your program. For example, in the screenshot below, I am dragging a line of code that detects whether one of the buttons is pressed into the program.

Untitled

This results in the following line of code being added to the program

input.button_is_pressed(Button.A)

<aside> 💡 It is important to note that the code you drag into the program might need some editing to adjust it to your program.

</aside>

A very simple program

We will now run a simple first program. Remove all code in the program and copy-paste the code below into the editor.

while True:
    press = input.button_is_pressed(Button.A)
    if press == True:
        led.plot(0, 0)
    if press == False:
        led.unplot(0, 0)

Next, click one of the run buttons in the simulator to run this program.