Random Number Sender

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?

Leave a Reply

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