Random Number Sender for the BBC Micro:bit

  • First, head to https://makecode.microbit.org/#editor
  • You will now have the code editor ready to use, so let’s get started. When we start we want to set a ‘radio group’ and show a tick so we know the Micro:bit is ready to go. In the ‘on start’ block add the blocks shown below:
Set Radio

Now we need a large block which does several things, and keeps doing them forever. You will put these blocks into the ‘forever’ block. This is what they do:

  • if button A is pressed (button A is the left one)
    • pick a random number between 0 and 9 and keep it safe in a variable
    • send the random number over the radio
    • show the number on the display (so we know what it was
    • pause for 2 seconds
    • set the display back to the tick so we are ready for the next one
Send Number

So each Micro:bit can receive the numbers as well as send we need a block for that. It uses an ‘on radio received’ block to show the number for 2 seconds and then wait for another.

Receive Number

Here are some things to try:

What happens if you change the number in the ‘radio set group’ block?

Can you send a message instead of a number?

By Mr Tansom

I have been a governor at Morelands since February 2008, and at Purbrook Park since November 2012. Back when I was at primary school there were no computers in classrooms, but by secondary we had some Commodore PETs and later BBC Micros. I ran one of the Code Club pilots in Morelands in 2012 and hope that by doing this some of the kids will get the chance to experience the sort of fun I had with my ZX81 and Spectrum back in the 80s.

Leave a Reply

Your email address will not be published. Required fields are marked *