<< Back to activities

Binary's UFO (micro:bit) kit - Wobble & Loose

This activity shows how to use Microsoft Make code - drag and drop blocks to test the UFO gyro capabilities.

Start >>

Step 1 - Wiring up Binary's UFO

Firstly wire up Binary's UFO to the BBC micro:bit as shown below:

Next >>

Step 2 - Access the BBC micro:bit editor to be able to "code" on the micro:bit

When you are coding using the BBC micro:bit, you need to do it through their online Editor. 

Click on this link www.microbit.co.uk to access the BBC micro:bit website. 

When it loads, click on "Let's Code" shown in the image below:

Next >>

Step 3 - Start a new project using the 'Block Editor'

There are lots of different types of editor you can use to program the BBC micro:bit. We are going to use the 'Makecode Editor' for this project. Click on the 'Let's code' button shown below.

Next >>

Step 4 - Set up your project

Next, we need to change the name of the script, click in the 'Untitled' box located next to the download button at the bottom of the page. This will allow you to change the name to something meaningful i.e. UFO wobble and loose.

Next >>

Step 5 - Start to Code

We will start with the forever function, this will constantly repeat code within it in the background. We will then add a while loop block which has a condition that evaluates a Boolean value of 'TRUE' or 'FALSE'.

Click on the 'Basic' tab, select the 'forever' loop and drag onto the blank page

Click on the 'Loops' tab, select the 'while true' loop, drag and snap it inbetween the 'forever' block

   

 

Next >>

Step 6 - Building the main code

Building on the previous step, we will now define a variable called 'wobble'. Click on the 'Variables' tab, select the make a variable button then call it ‘wobble’

Click on the 'Variables' tab, select the 'set wobble to' block and drag it into the 'while true' loop

   

Click on the 'Input' tab, select the 'acceleration (mg) x' block, drag and snap it onto the right of the 'set wobble to' block

    

 Click on the 'Logic' tab, select the 'if' statement, drag and drop it underneath the 'set wobble to' block

   

Click on the 'Logic' tab again, select the ' or ' block, drag and snap the block to the right of the 'if' statement

   

Click on the 'Logic' tab, select the '0 < 0' block, drag and drop it into the first black space of the ' or ' block and change the ‘<’ to ‘≥’.

   

Click on the 'Logic' tab, select the '0 < 0' block, drag and drop it into the second black space of the ' or ' block and change the ‘>’ to ‘≤’

   

Click on the 'Variables' tab, select the 'wobble' variable, drag it and replace the first '0' in oth of the 0<0 blocks

    

Change the second '0' on the 'wobble < 0' block to '900'

 

Change the second '0' on the 'wobble > 0' block to '-900'

Next click on the 'Basic' block, select the 'show leds' block, drag and place the block in the 'do' section of the 'if' statement

   

Next create a small 'X' shape in the 'show leds' block

Click on the 'Basic' tab, select the 'pause (ms)' block, drag and place underneath the 'show leds' block

   

Next duplicate the 'show leds' block and place the block underneath the 'pause (ms)' block

   

Make the 'X' bigger in the 'show leds' block

Click on the 'Game' tab, select the 'change score by 1' block, drag and place underneath the second 'show leds' block

   

 

Next >>

Step 7 - Ending the sequence

 Click on the 'Logic' tab, select the 'if' statement and drag it underneath the first 'if' statement

   

Click on the 'Logic' tab, select the '0 < 0' block, drag and snap the block to the right of the second 'if' statement and then change the ‘<’ to ‘≥’.

   

Click on the 'Game' tab, select the 'score' block, drag and replace the first '0'

   

Change to second '0' to a value you want the code to stop at

Next click on the 'Game' tab, select the 'game over' block and drag it into the 'do' section of the second 'if' statement

   

Next >>

Step 8 - Flashing the LED's

Now we need to add the code which will make Binary's UFO lights come on.

 Click on the 'Loops' tab, select the 'while true' loop and drag it onto the page

 

Click on the 'Logic' tab, select the ' or ' block, drag and snap it to the right of the 'while true' loop, replacing the 'true'

    

Click on the 'Logic' tab, select the '0 < 0' block, drag and replace both the '0's

   

Click on the 'Variables' tab, select the 'wobble' variable and drag and replace the first '0' in each of the '0 < 0' statements

   

Change the '0' on the first 'wobble < 0' statement to '-150' and chang the '0' from the second 'wobble < 0' statement to '150'

Click on the 'Pins' tab, select the 'digital write (0,1)' block, drag and drop it in the 'do' section

   

 Click on the 'Basic' tab, select the 'pause' block and drag it underneath the 'digital write (0,1)' block

   

 Duplicate the 'digital write (0,1)' block two times and place them underneath the 'pause' block

   

Duplicate the 'pause' block once and drag it underneath the third 'digital write (0,1)' block

   

Duplicate the 'digital write (0,1)' blockonce more and place underneath the second 'pause' block

   

 Change the pins on both the first and second 'digital write (0,1)' blocks from 'P0' to 'P1'

Change both the 'pause' blocks from '100' to '500' - this is the amount of time the micro:bit will wait untill it executes the next command

 Change the pins on both the third and forth 'digital write (0,1)' blocks from 'P0' to 'P2'

 

Next >>

Step 9 - Adding sound

Now we need to add sound so that we know the score has been reached

Click on the 'Logic' tab, select the 'forever' block and drag it onto the page

Next click on the 'Loops' tab, select the 'while true' loop, drag and place inbetween the 'forever' loop

    

 

Click on the 'Logic' tab, select the '0 > 0' block, drag and snap the block to the right of the 'while true' block replacing the 'true' block

   

Click on the 'Game' tab, select the 'score' block, drag and replace the first '0'

   

Change the '>' symbol to the '≥' symbol

Chnage to second '0' to the value you wanted the code to stop at in the previous step

 Click on the 'Music' tab, select the 'play tone' block, drag and place inbetween the 'do' section of the 'while true' block

   

Duplicate the 'play tone' block two more times and place them underneath the first 'play tone' block

   

Change the 'play tone' and 'beat' to any desired variable

Next >>

Step 10 - Ready to test!

You are ready to test your code !! You can do this before you put it on Dimm. On the right side of the editor is a 'Virtual' micro:bit - its a version of the real thing that you can use to test. 

At the top of your editor, click on the 'Run' button. 

Next >>

Step 11 - Does it work?

 Now on the virtual micro:bit, move your mouse around and see if the "game" works, when the game ends, the micro:bit should play a sound

Next >>

Step 12 - Download the code ready for Binary's UFO

It is now time to see it work on Binary's UFO. 

On the top of the editor is a button that says 'Download' - shown below in a purple box

 

Next >>

Step 13 - Find your downloaded code file

Click on the downloaded file at the bottom of the browser - select 'Show in Folder'

This will open the folder containing all your downloaded files - this will include a file called something like 'microbit-UFO-wobble-and-loose.hex'

Next >>

Step 14 - Plug in the micro:bit

Now you need to plug the micro:bit on Binary's UFO, into your computer - using the USB cable that came with the micro:bit.

When you plug it in, a window should pop up on screen that looks a bit like this:

Next >>

Step 15 - Paste the code file to the micro:bit

Right click on a blank space within the micro:bit folder and choose 'Paste' - it will display a window a bit like the below as it copies the file to the micro:bit.

Next >>