Create a Simple Counter

Build an app to help someone count objects. It could be used to count people going into a concert or the number of cars going down a street.

Step 1

Create a blank project using the JavaScript Blocks Editor.

Go to microbit.org/code and click on Let's Code

Step 2

In computer programming we use variables to store information. Variables are like boxes that can hold the information our program needs. It might be a number, a string (text, or something else. Programs can store variables and also change their contents.

Create this code to make a new variable that will hold the number of objects counted so far. It needs to be set to be 0 as soon as the program starts.

Tip: The unit can be renamed to count.

Step 3

Add this code to your program to increase the count by one every time button A is pressed.

Think about why the forever loop is needed.

Use the 'Download' button to compile your code and download it onto your computer.

Upload the Hex file onto your micro:bit and test it out.