<< Back to activities

Binary's UFO (micro:bit) kit - Launch Sequence (not RGB LED Strip)

This activity will use the UFO LEDs and Buzzer to create noise and lights according to a countdown

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 https://microbit.org/ 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 'Start with this editor' button shown below.

Next >>

Step 4 - Set up your project

To begin setting up your new project, click on the 'New Project' button

 

 

 

When the new project loads you will see two blocks on the page, an 'on start' and 'forever' block. Delete these blocks by dragging them over the tabs to the left

 

  →  

 

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 Launch

 

  →  

 

 

Next >>

Step 5 - Start to Code

First, click on the 'Basic' tab, select a 'on start' block and drag it onto the page

 

We then need to define a variable to show a countdown timer

Click on the 'Variables' tab, 'make variable...', and type 'counter'. this will create the variable.

Select the 'set counter to' variable and drag it into the 'on start' block

    • Change the value of the '0' to any desired value, for this purpose it will be changed to '5'

Next >>

Step 6 - Stop the countdown starting automatically

Now we need to create a function to stop the countdown starting automatically

Click on the 'Variables' tab, select the 'Make a variable...' and type 'countingdown'. The drag the 'set countingdown to' block underneath the 'set counter to 5' block

   

Next click on the 'Logic' tab, select the 'false' block, drag and snap it to the right of the 'set countingdown to' variable

Now we need to create a function to start the countdown using a button

Click on the 'Input' tab, select the 'on button A pressed' block and drag it onto the page

  • Next we need to change the button to button B, this is done by click on the 'A' and change it to 'B'

Click on the 'Variables' tab, select the 'set countingdown to' variable and drag it in-between the 'on button B pressed' section

   

Click on the 'Logic' tab, select the 'true' block, drag and snap it to the right of the 'set countingdown to' variable

   

Now we need to create a little bit of code to make the button work

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

 

Click on the 'Basic' tab again, select the 'show number' block and drag it into the forever loop

     

Click on the 'Variables tab, select the variable 'counter', drag and place over the number '0' from the 'show number' block

   

Next click on the 'Logic' tab, select the 'if' statement, drag and place it underneath the 'show number counter' block

   

 Click on the 'Logic' tab, select the '0 = 0' block, drag and place to the right of the 'if' statement

   

 Click on the 'Variables' tab, select the 'countingdown' variable, drag and drop it over the first '0'

Next click on the 'Logic' tab, select the 'true' statement, drag and place it over the second '0'

Click on the 'Basic' tab, select the 'pause' block, drag and drop it into the 'then' section of the 'if' statement

   

Replace the '100' ms with '1000' ms

 Click on the 'Variables' tab, select the 'change countingdown by' variable, drag and place underneath the 'pause (ms) 1000' block

Click on 'countingdown' and change it to 'counter'

Replace the '1' with '-1'

Click on the 'Logic' tab, select the 'if' statement, drag and drop underneath the 'change counter by -1' block

Click on the 'Logic' tab, select the '0 < 0' block, drag and place to the right of the second 'if' statement

Click on the 'Variables' tab, select the 'counter' variable, drag and drop it over the first '0' 

Click on the '<' symbol and change it to the '≤' symbol

 Replace the '0' with '-1'

Next click on the 'Variables' tab, select the 'setcountingdown to' block, drag and drop it into the 'then' section of the second 'if' statement

Click on the 'Logic' tab, select the 'false' block, drag and drop to the right of the 'set countingdown to' variable

Next >>

Step 6 - Changing the countdown timer

Here we are going to create a bit of simple code to add +1 or -1 from the counter 

 

To +1 to the countdown

Click on the 'Input' tab, select the 'on button A pressed' block and drag it onto the page

Click on the 'Variables' tab, select the 'change countingdown by 1' variable and drag into the 'on button A pressed block

Next click on 'item' and rename it to 'counter'

 

To -1 from the countdown

Click on the 'Input' tab, select the 'on button A pressed' block and drag it onto the page

Click on the 'A' dropdown menu and select 'A+B'

Click on the 'Variables' tab, select the 'change countingdown by 1' variable and drag into the 'on button A+B pressed block

Next click on 'item' and rename it to 'counter'

Click on the '1' and change it to '-1'

 

Next >>

Step 7 - Flashing the LED's

* If you have a BinaryBots UFO kit with an LED strip, please go to the new Flashing the LED's activity Here

 

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

   

Click on the 'Advanced' tab, then the 'Pins' tab, select the 'digital write (0,1) to pin' block. Drag and drop the block into the 'do' section

   

Change the pin from 'P0' to 'P1'

 Click on the 'Basic' tab, select the 'pause (ms) 100' block, drag and drop the block underneath the 'digital write' block

   

 Change the '100' ms to '500' ms

Duplicate the 'digital write' block two times and place them underneath the 'pause (ms) 500' block

   

On the second 'digital write' block, change the '0' to '1' and on the third 'digital write' block change the pin from 'P1' to 'P2'

   

Duplicate the 'pause (ms) 500' block and drag into place underneath the 'digital write pin P2 to 0' block

Duplicate the 'digital write pin P2 to 0' block once and place underneath the second 'pause (ms) 500' block

Now we need to add this sequence to the countdown

Click on the 'while true' bit of code and drag it underneath the 'if' statement from the bit of code starting the countdown sequence

Next >>

Step 8 - Adding sound

Click on the 'Logic' tab, select the 'forever' loop and drag it to a blank space on the page

Click on the 'Loops' tab, select the 'while true' block and drag it into the forever block

 

Click on the 'Logic' tab, select the '0 < 0' block, drag and place to the right of the 'while true' statement

   

Click on the 'Variables' tab, select the 'counter' variable, drag and drop it over the first '0' 

  ⇒ 

Click on the '<' symbol and change it to the '≤' symbol

 Replace the '0' with '-1'

Click on the 'Music' tab, select the 'play tone' block, drag and snap it in the 'do' section of the 'while true' loop

   

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

Change the 'tone' and 'beat' on all three 'play tone' blocks to your desired value

Next >>

Step 9 - Putting all the code together into one script

From the previos stps you should have now created: a countdown timer, a way to change the countdown timer and flash the LED's

Your page should have 7 bits of code on it that looks something like below:

 

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 left side of the editor is a 'Virtual' micro:bit - its a version of the real thing that you can use to test. 

 

Next >>

Step 11 - Does it work?

Now, on the virtual micro:bit, click on button 'B' this will initiate the countdown. When the countdown reached '0', the sound created earlier should start to play

      

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 'Compile' - shown below in a red box

Click on it - the page will download a file to your computer

 

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-Binary-s-UFO-Launch.hex'

Right click on the file and choose to copy it (this is ready for the next step)

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 >>

Step 16 - See if Binary's UFO has taken off!

Next >>