How to program a micro:bit with MakeCode

Flashing Heart

Description

When learning something new, the best first project is always a simple one that teaches basic skills and has a quick reward. That’s why my go-to first project for the micro:bit is the flashing heart. It teaches a little about events, highlights some of the features of the micro:bit, and provides an easy path into programming. All this project does is create a blinking heart on the micro:bit LED screen. I have added a few more steps to show how loops and events work.

Materials

Designing the Project

Develop a problem statement

This project is really about getting started with programming and learning what’s on the micro:bit so the tasks that we want to perform are designed to provide an overview of these.These four steps cover the basics of starting to program a micro:bit using MakeCode Blocks:

Step

Problem Statement

Coding Skills Learned

1

Draw a heart on the screen

  • How to use blocks
  • How to use the simulated micro:bit
  • How to download code to the micro:bit
  • How to use the LED array

2

Make the heart blink off and on forever

  • The concept of Loops
  • Creating a simple animation

3

Make the heart blink 5 times

  • Loops
  • Iterations

4

Make the heart blink 5 times when Button A is pushed

  • Inputs
  • Actions

 

Write the Algorithm

If a student is brand new to coding or to the micro:bit, this phase is something that you can use to step through the directions for your new users. Writing the algorithm, even for a beginner, is useful because it helps develop computational thinking. These algorithm examples use some terminology directly from MakeCode because this project is about learning how to use MakeCode:

Step 1 Algorithm

To Start:

Display a heart icon 

 

Step 2 Algorithm

Do Forever:

Display a heart icon

Clear the screen

 

Step 3 Algorithm

Do 5 times:

Display a heart icon

Clear the screen

 

Step 4 Algorithm

On Button A pressed:

Do 5 times:

Display a heart icon

Clear the screen

Write and Test the code

Here is the copy of my final version of the code. After you extract it, double-click on it and it will open in MakeCode:

Flashing Heart

The video below walks through writing the code in MakeCode:

 

Concepts Involved

Loops

Events