Science Oxford Logo

Editing the second micro:bit code

Open the code

Unplug your original micro:bit and plug in the new one.

Open a new file in Mu, then copy-and-paste the second micro:bit code.


Edit radio.config(channel=7) to be your channel number.


audio

One thing you probably noticed, is that the second micro:bit makes a sound when it receives a message.

Turn the micro:bit over and look on the back - the round black component in the middle is a speaker - this is only on V2 micro:bits.

If your micro:bit does not have a speaker, then it is a V1 micro:bit and this code will not work. Download this code instead, and skip to the next section.


Two lines make this audio code work, try to find them in the code.

import audio
audio.play(Sound.GIGGLE)

Change the sound to one of these options.


Receiving messages

The micro:bit is set up to listen for messages over the radio waves. Whatever it finds, it puts in the variable message

If no messages have been sent, then the micro:bit receives None .

To help make the die work, we have added a new if criteria - messages will only show on the display if they are not None .


Editing the code

Do you want to add more features to this micro:bit, or the original one?

Remember which micro:bit is which - it can be confusing to work out which micro:bit to Flash which code to! You will need to keep swapping your micro:bits.