Create a program that uses the micro:bit's compass to display the cardinal directions (N, S, E, W) on the LED screen.
BBC micro:bit
New project at https://python.microbit.org/v/3
Your task is to create a program that:
Reads the compass heading from the micro:bit
Determines which cardinal direction the micro:bit is pointing
Displays the corresponding letter (N, S, E, or W) on the LED screen
Here's the basic structure of your program:
from microbit import *
# Ensure the compass is calibrated
compass.calibrate()
while True:
# Get the compass heading (0-360 degrees)
heading = compass.heading()
# Your code here: Determine the direction and display it
# Short delay to prevent too rapid updates
sleep(100)
Use this to help you determine which range of degrees corresponds to each cardinal direction:
N: 315°-45°
E: 45°-135°
S: 135°-225°
W: 225°-315°
Use if, elif, and else statements to check the range of the heading
Remember that North is a special case: it includes both 0°-45° and 315°-359°
Use display.show() to display the letter on the LED screen