Compass Microbit
Compass Microbit
Compass
{Introduction }
This tutorial shows you how to create a program that displays which direction the
micro:bit is pointing. Let’s get started!
{Step 1}
First, store the compass heading of the micro:bit in a variable called degrees
in the forever loop.
forever
https://makecode.microbit.org/projects/compass 1/6
8/22/24, 4:17 PM Compass
{Step 2}
If degrees is less than 45 , then the compass heading is mostly pointing
toward North. Show N on the micro:bit.
forever
{Step 3}
If degrees is less than 135 , the micro:bit is mostly pointing East. Show E
on the micro:bit.
https://makecode.microbit.org/projects/compass 2/6
8/22/24, 4:17 PM Compass
forever
{Step 4}
Go to the simulator and rotate the micro:bit logo to simulate changes in the
compass heading.
{Step 5}
If degrees is less than 225 , the micro:bit is mostly pointing South. Show S
on the micro:bit.
https://makecode.microbit.org/projects/compass 3/6
8/22/24, 4:17 PM Compass
forever
if degrees <
45 then
{Step 6}
If degrees is less than 315 , the micro:bit is mostly pointing West. Show W
on the micro:bit.
https://makecode.microbit.org/projects/compass 4/6
8/22/24, 4:17 PM Compass
forever
{Step 7}
If none of these conditions returned true, then the micro:bit must be pointing
North again. Display N on the micro:bit.
https://makecode.microbit.org/projects/compass 5/6
8/22/24, 4:17 PM Compass
forever
else
{Step 9 }
If you have a micro:bit, click Download and follow the screen instructions. You
will have to follow the screen instructions to calibrate your compass.
https://makecode.microbit.org/projects/compass 6/6