7. Conversation between 2 micro:bits

A conversation between 2 Micro:Bits

We will now play a game against one another, in which we’ll need Micro:Bits.

You will learn:

  • • How to program your Micro:Bits so that they can communicate with each other.
    • How to program a radio signal.
    • How to send a signal by radio.
    • How to receive a signal by radio.
    • How to multiply numbers and variables.

Register before you start the exercise. Click the button below and sign up.

Click here

ORIENTATION

Take a look at the example and consider the following questions:

  • What should I do?
  • What are the goals?
  • What are the expectations?
  • What can I already do?
  • What do I still have to discover?

PREPARATION

View the steps under 'Go!'. Then answer the following questions:

  • Which steps should I follow?
  • Which steps can I follow?
  • How much time do I need?
  • What tools do I need?

Go!

Do the steps one by one. Do you not remember how to do it? View the hints or download the solution.

STEP 1

Make a message

Before sending something to each other, we will need to produce a message.
We want to send multiple messages. In order to that, we will have to make a variable. We can produce our messages in the variable.

1

Every time we press the A-button, our variable has to increase by 1. We’ve done this a few times before.

We don’t want to send an infinite amount of messages. We’ll limit the amount to 5 messages. That means our variable will have to stop counting once it’s more than 5.

  • If message <=5 then: show message
    • If message >=5 then: clear screen, set message to 0

Do you know which blocks you need? Get started.

Our Micro:Bit now shows the numbers from 1 to 5. We can already send these numbers to the other Micro:Bit. But that’s rather BORING.

Task:
• Think of 5 fun icons you can send.
• If message = 1 then: show message, ...
• Make the icons appear on your Micro:Bit when you press the B-button.

 

If you’ve programmed everything correctly, you can make the Micro:Bit show a different number by pressing the A-button. If you press the B-button, it will show the corresponding icon.

STEP 2

CONFIGURING THE RADIO

Before we can let our Micro:Bit send out a message, we’ll first have to “configure the radio”. Start by taking a look at the menu: Radio

36

In order to make two Micro:Bits talk to each other, you have to set the radio on both Micro:Bits to the same group. Run this program “at start-up”. You can pick any number between 0 and 255. There are many channels you can use if you want to send a message.

STEP 3

SENDING THE MESSAGE

When we shake our Micro:Bit, it has to send the message.
Take a look at the menu “Radio”. Which block can you use?

 

STEP 4

RECEIVING THE MESSAGE

The only thing we need to do now, is receive the message.
When the Micro:Bit receives the message, it has to show the icon.

Put this code on 2 Micro:Bits and you can send messages.

Good job, you can now secretly message one another. Can you adapt the code so that you can send sentences?

REFLECT

Look back at the project you just made. Ask yourself the following questions:

  • Does the program work as I expected? Why / why not?
  • What works well?
  • What works less well?
  • How can I approach it differently?

Download

Click the link below to download a sample solution.