Step counter

Using the commands:
– on start,
– show string,
– on shake,
– change by 1,
– forever,
– show number

create a program where the micro:bit counts steps and displays the step count on the screen. At the beginning, display the words Step counter on the screen so you know what you are counting. To successfully complete the task, you must use a variable to store the count of steps. Think of a variable as a memory where values are stored and it has its own name. To use the desired variable in the program, you call it by its name.

Instructions for creating the program

1.

Inside the on start block, place the show string command and write Step counter into it.

3.

Inside the on shake block, place the change by 1 command and set the variable Step counter as its argument.

2.

Create a variable by clicking on option Make a Variable within the Variables category of commands. A new window will open where you will write the variable name, in this case Step counter.

4.

Display the step count using the show number command, and set the variable Step counter inside it. By using the forever block, you ensure that this variable is displayed on the screen continuously.

JavaScript code

Although your programs are created using Blocks, you’ll need to copy the JavaScript code of your created program for solving certain escape room tasks. After you create a program in MakeCode Blocks editor, you can see its JavaScript version by going to JavaScript mode.

Copy the JavaScript code from your Step counter program and paste it into the box below:

 

This publication reflects the views only of the author, and the Commission cannot be held responsible for any use which may be made of the information contained therein.

Tags: