Microbits have an in-built compass that detects magnetic fields. This function is always working even when we don’t code it to work. We can use this function to detect North and code the Micro:bit to tell us which direction we are facing.
https://makecode.microbit.org/projects/compass
2. 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. You will need the Logic blocks IF THEN, comparisons GREATER THAN, LESS THAN, and the Boolean OR block. The two comparison blocks go inside the OR block. Then drag those combined blocks into the IF THEN conditional block.
3. To add more directions simply add more of these IF statements, you can duplicate the IF statement by holding your finger on it, and pressing duplicate.
4. IMPORTANT NOTE: CHANGE THE “OR” to an “AND” for E,S,W directions.
Try to display the directions North-West, North-East, South-East, South-West as well as the other cardinal directions. What parts of the code do you need to change? What is strange about these numbers? What can we do to fix them?
Hint: round down!