Skip to main content

Micro-Bit: Interface and Running Code

Objective 

Roboteers will understand how to run a code using a visual interface.

Essential keywords

Block Code


Attention (5 Min.)

You can run a software such Minecraft using a MicroBit, which is a hardware. Let's watch this video!

Learners Guidance

Introduction to Micro-Bit Interface

Micro-bit Editor page of a blank project

The code editor is browser based, so you can use any computer including Chromebook. It is the MakeCode Editor.

To begin, create a new project from the My Projects area. This will generate a page very similar to scratch or other block coding, with the addition of converting the current blocks to written code in JavaScript at the top of the screen. This can be useful for showing how written code and block code are related.

To the left shows a simulation of what the micro-bit looks like. When you update working code, the picture on the left will simulate what the code will do in real life. This makes debugging code much easier since you can check the output before you place it on the Micro-bit controller.

The middle section consists of all the blocks of code, separated into their types, such as logic, variables, arrays/lists, etc. They are also color coordinated for ease of navigation.

The right section is where all the code goes. It will start with two blocks, a "forever" block and "on start" block. To add more code, drag and drop from the middle section. Some code blocks have little indents on the top and bottom of them, indicating they can be connected in chains to other blocks of code.

Using Block Code

Block code takes the hassle of syntax out of traditional coding. Rather than typing every function and output line by line, drag and drop the code in the order you wish it to execute. All blocks in the area will be executed and run. Certain blocks will run first before others depending on the code. "On start" will execute first before anything else, If/Else statements will only execute if certain conditions are met, and forever loops will execute each time the code iterates through, forever.

Lines of code with indents on the top and bottom will do their task when placed inside a pocket of code. They can be stacked with other code to make chains of code that will work in descending order.

Lines of code that have a pocket for more code to go but do not have upper or lower indents for code to be added outside cannot be stacked with others. These usually consist of different input requirements, and will run all code placed inside the pocket once their beginning condition is met.

Lines of code that do not have either indents or a pocket for more code are conditions or variables. They are used to fill in circular spots in code that will run if certain things happen. They are the actual data that is used to check whether or not something has happened for further code to use, and do not run as executable code on their own.

The top three will do their task once ran, the middle three will run whatever code is placed inside of them once their beginning condition is met, and the bottom is an example of a condition.

Running Code

The code editor is browser based, so once you have code that is finished, save it to your computer and download the HEX file. Once downloaded, drag/drop it into the micro-bit controller on your computer in the USB/external section. Once it uploads, the micro:bit will run the code indefinitely. You can press the reset button on the micro-bit to reset the code from the top.

Alternatively, there is a more streamlined way to get your code onto the Micro:bit but it requires a little bit more setup. To connect your Micro:bit directly to MakeCode, first click on the 3 dot menu to the right of the download button and select "Connect device"

Then, select your Micro:bit in the popup and click connect.

Now, when the download button is pressed, the code will be automatically downloaded onto the Micro:bit as long as it is connected to the computer.

 

3.  Explore (25 - 30 Min.)

Time to customize!

4. Share (Min.)

Peer review! Students can share their work with peers for constructive feedback and then use this feedback to revise and improve their work.

5. Closure (Min.)

Review Content

6. Evaluate

Students reflect on their performance. Give positive and constructive feedback on each student.

Essential Questions

What is block code?

How do stacks of blocks execute code?