Skip to content

Compass

Compass

Welcome! This guided tutorial will show you how to program a script that displays which direction the micro:bit is pointing. Let’s get started!

Display the direction that the micro:bit is facing using the compass.

Step 1

Create a loop that will continuously update the reading of the compass.

Step 2

Store the reading of the micro:bit in a variable called degrees.

Step 3

If degrees is less than 45 or greater than 315, then the compass heading is mostly pointing toward North. Display N on the micro:bit.

Step 4

If degrees is less than 135, the micro:bit is mostly pointing East. Display E on the micro:bit.

Step 5

If degrees is less than 225, the micro:bit is mostly pointing South. Display S on the micro:bit.

Step 6

If none of these conditions returned true, then the micro:bit must be pointing West. Display W on the micro:bit.

Link: https://makecode.microbit.org/_DaaYzF7Xmbfd