In each game there must be at least 1 Bee player.
This player will first find the Pollen, and then find all the Flowers to pollinate them.
You will need:
1 Battery box and batteries
1 USB programming cable
You will also need a computer that is connected to the Internet and has a USB input in order to program each micro:bit.
On the computer, point your browser to https://makecode.microbit.org/ and select New Project. Name the Project "Bee."
The "on start" Block
We'll use the "on start" block, to setup the game.
Set Radio Signal Strength
Under "Radio" then "... more" we can find the "radio set transmit power" block.
Click on that block and drag it into the "on start" block. Then change the value in the white box to 0 by typing in the white box or moving the slider.
The value to 0 means we will be limiting the radio transmission to the lowest possible setting, which means the micro:bits will need to be within around a meter of each other to be able to "talk" to each other.
The next step is to create 3 variables, using the "Make a Variable..." button inside the "Variables" menu.
The variables should be:
To do this, go to
Then name the variable and click OK
Repeat this for the other two variables. Your Variables should look like this:
Set the Values of the Variables
Now we are going to use the "set" block to set all 3 variables to 0 at the start of the game.
In the Variables menu, click the "set" block and drag it on to the "on start" block beneath "radio set transmit power." The variable for this one will default to "count".
Now drag another "set" block to "on start" and, using the drop down, change the variable name to "game."
Then drag another "set" block to "on start" and, using the drop down, change the variable name to "pollen."
Your "on start" block should now look like this:
Add LED Display
The last step in the "on start" block is adding an LED display of "B" to indicate this micro:bit is running the Bee code. Go to Basic, and drag the "show leds" block below the variables, then use your mouse to click the grey boxes and form a B shape.
The "on start" Block Should Look Like This:
The Code that Starts the Game
We want pressing the "A" button on the micro:bit to start a 30 second countdown timer, giving the Pollen and Flower players time to hide.
To do this, go to the Input menu and click on the "on button 'A' pressed" block and drag it on to the workspace.
To create the countdown timer we'll go to Loops, click on the "for index from 0 to xx" block and drag it in to the "on button 'A' pressed" block.
Change the value in the white circle to "30".
We want the countdown timer to appear on the Bee's micro:bit screen. To do this we'll go to the Basic menu and drag "show number" into the "on button 'A' pressed" block.
Then we will put the index variable in the block, replacing the zero in the white circle above. To do this, go to Variables and select "index" and drag it on top of the "show number" block.
NOTE: We didn't create the "index" variable - Makecode automatically created it as soon as we inserted the "for index from 0 to xx" block above.
We want the countdown to last 30 seconds. To do this, we will put a delay of 1 second between each number. In the Basic menu, click the "pause (ms)" block and insert it into the "for index from 0 to xx" block.
We will then use the "pause (ms)" block from the Basic menu to create a 1 second delay between each number (this will make it count in seconds). Click on the value in the white circle and you'll see a drop down of time increments. Select 1 second from the list - the inserted value will be shown as 1000ms (1000 miliseconds = 1 second).
When the "for index from 0 to xx" block completes its task of counting down from 30, we want to display a message so the Bee knows it's time to start searching.
To do this, go to the Basic menu, click on the "show string" block and drag it into the "on button A pressed" block.
Click on the string where the text says "Hello!" and change replace it with "GO!"
The final step in the block is to set the Game counter. In Variables, click on "set <variable> to" block and drag it to the bottom of the "on button A pressed" block.
Next, select the "game" variable from the drop down list and change the value in the white circle to 1.
Your code should now look like this:
Finding Pollen and Flowers
When the A button is pressed on the micro:bit, the game is underway and the Bee must find Pollen and Flowers. Remember, we set the radio transmit area to 0 in the "on start" block. That means the radio only works within a distance of about 1 meter so the Bee will have to find the other players to see what messages those micro:bits are sending.
To make the Bee micro:bit start searching for signals from the Pollen and Flower micro:bits, we must do the following.
In Radio, click the "on radio received receivedString" block and drag it to the work area.
Since the Bee's micro:bit will be receiving strings from the other players' micro:bits, we need to define what we're looking for ("Pollen" or "Flower") and then tell the micro:bit what do do based on the value received. To do this we'll be using If blocks. The first thing we'll check is whether or not the game has started.
In the Logic menu, click on the "if" block and drag it into the "on radio received receivedString" block.
If you'd like more information on how this block works, see the Makecode help section on the "If" block.
We want to replace the "true" drop down with a comparison - so that we can compare the value to what we want the value to be. In this case, we want the game to have started, so we're looking for the "game" variable to be set to "1" (we set this in the final step of the "on button A pressed" block above).
Go to Logic and then select the comparison block that looks like this:
Drag it on top of the if block:
What we are looking for is the "game" variable to be set to 1. To look for this comparison, we'll drag the "game" variable from the Variables menu.
Then drag it on top of the left value of the "If" block to the left of the equal sign:
Finally, change the value from 0 to 1. This tells the micro:bit that if the "game" variable is set to 1, run the rest of the if blocks nested within. But if the "game" variable is not 1, then it will do nothing.
Check for Pollen
The Bee cannot pollinate the Flowers unless it has Pollen, so the Bee must find the Pollen player first. Inside the "if" block that makes sure the "game" variable is set to 1, we will be inserting another "If" block.
Following the same steps as above, drag a comparison block on top of the new "If" block. Then drag and drop the "pollen" variable on top of the left side of the comparison equation, leaving the comparison value on the right of the equal sign 0.
This means that if our "pollen" variable is 0, then run the next nested block.
Our next nested block will check if the value we receive from a player's micro:bit is "pollen." Click another "if" block and drag it into the "if pollen = 0" block.
In this "if" we will be comparing text strings, so insert the following comparison block on top of the new "if" block.
On the left-hand side we will put "receivedString", we can do this by dragging the oval red block from the "on radio receivedString" header.
Then we will put "pollen" on the right-hand side.
Your code should now look like this:
We've checked that the Game has been started, that the Bee has no pollen, and that the text string received from another player's micro:bit is "pollen." If all of these are true, we'll run the next block that is inserted in this "if" block. In this case, we'll set the Bee's "pollen" variable to 1 and play a little sound to indicate the success of finding pollen.
To play the sound, go to Music and drag the "play" block into the "if" block.
Then go to Variables and drag the "set" block into the "if" block. Change the variable to "pollen" and the value to 1.
It should look like this:
So far, we've checked that the game has begun (variable "game" = 1) and the Bee didn't have pollen ("pollen" = 0), then we found pollen from the Pollen player's micro:bit ("receivedString = "pollen"") meaning that set of "if" blocks is complete.
But now that the Bee has pollen, it's time to find the flowers. We'll add a new "if" block that checks the "receivedString" for a different message.
Go to Logic and grab an "if" block and insert it in the "game" if block, below the other nested "if" blocks.
Drag a text comparison block on top of the new "If" block. Then click on the "receivedString" in the "on radio received receivedString" block and drag it on the left side of the comparison. In the right side of the comparison, enter "Thanks."
We want to keep track of how many Flowers the Bee finds, so in Variables we'll click on the "change" block and drag it in to the "If" block. Change the variable to "count" and ensure the value is 1. You should have something that looks like this:
Code in the Forever Block runs all the time. This means that as soon as it finishes, the block starts again. We're going to do two things in the Forever loop. First, we'll send a message from the micro:bit that it's a Bee carrying Pollen. Second we'll create some visual displays that show what's happening.
If you don't already have a forever block on your workspace, you can drag one over from the Basic group.
Send the Bee with Pollen Message
We'll be using "if" blocks again here. We want to check that the game is underway ("game" = 1) and that the Bee has pollen ("pollen" = 1). That means we'll be adding two "if" blocks to the forever block.
In the first "if" block, change the comparison to:
Then set the variable on the left to "game" (select and drag from the Variable menu) and set the value on the right to 1.
Insert another "if" block inside that one, change the comparison as above, make the variable "pollen", and make the value on the right 1.
You should now have this:
Now we want to send a message to the other micro:bits in the area, telling them that we're a Bee with pollen. To do this, in Radio, click on "radio send string" and drag it into the forever block and change the string to "Bee."
Setup Visual Display Elements
To give the Bee player some visual cues on the micro:bit, let's add an LED display and show the number of Flowers that we've pollinated.
From Basic, click and drag the "show leds" display into the forever block, beneath the "radio send string." Change the grey boxes to something like the following example (or whatever you'd like!).
We're going to alternate between this led display and the number of Flowers polinated. From Basic, click and drag "pause" beneath the "show leds."
Then, from Basic, click and drag the "show number" block beneath the "pause" block. "Count" is the total number of Flowers pollinated, so click on that variable in the Variables menu and drag it on top of the "show number" block.
Finally, drag another "pause" block beneath the "show number" block. I've set the value for both "pause" blocks to 500 - but you can experiment with different pause values to find what works best for you.
My finished forever block looks like this:
Finally, we need to add our code to the Forever block. If this is not showing, then you can find it in the "basic" menu.
This is code which will run all the time, as soon as it has finished the block, it will start again.
We are going to use "if" blocks to ask questions again.
Like before, we are going to use the equals comparison, the left-hand side is the game variable, the right-hand side is 1.
If the game is in play, we can continue to a second if question. This time, the left-hand side is pollen (variable), the right-hand side in 1.
If that was correct (or if you are carrying pollen), then we want to do "radio send string "bee" " block (in Radio), this will mean your Micro:bit is sending the message that it's a bee carrying pollen to any close micro:bits.
The next steps are just visual to give you something to look at on the display and see what is happening.
I've added a "show leds" to show a dot, which is to represent you are carrying pollen (this is inside the if block for pollen = 1), a pause for 500ms so you have time to see the picture, then "show number" with the "count" variable, this shows how many flowers you have pollinated.
Another pause for 500ms (you might want to increase these, experiment with your code).
Here's all the code together:
Be sure to save your work!
The final step is adding the code to a micro:bit. See the micro:bit guide for programming here: https://microbit.org/get-started/user-guide/transfer-code-to-the-microbit/ if you require assistance with this step.
You also need Flower and Pollen micro:bits to play the game.