Step Counter
The accelerometer in the Micro:bit can detect if the Micro:bit is being shaken (or tilted).
Check out the Watch or Step Counter under the Fashion heading for another tutorial.
This tutorial uses a variable (think of this as a bucket to store a number
in) to keep track of how many times the Micro:bit is shaken. It then uses the display
number block to display how many times the Micro:bit has been shaken.
- In the Variables menu, click on Make a Variable… and call it steps
-
You will see several options show up. Drag the "Set Steps to 0" block to the "On start" block. When the Micro:bit starts up, it will set the counter to 0.
-
Now we need to have it add one to steps every time the Micro:bit gets shaken.
Under the Input menu drag an On Shake block onto the programming area and
place a "Change Steps by 1" block inside.
-
Lastly, we need to be able to see how many steps we've walked (or times the
Micro:bit has been shaken). From the Input menu drag an On Button A Pressed
block onto the programming area. Inside it place a Show Number block from the
Basic menu, but instead of 0, we need to show the value of steps. Under the
Variables menu, drag the step oval to cover the 0. Wherever you have an oval
with a number in it, you can place a variable as well.
Next "Steps"!
- Can you add a picture that flashes every time you shake the device or
take a step?
- Can you create a step coutner that counts 2 or 3 times every time it gets shaken?
- Can you make the step counter constantly show the number of steps? Check out the online
tutorial.