Lesson 3: Compass North Program
To Know - To Know - Pseudocode standards.
Selection, iteration and variable program structures.
To Be Able To - Design a program using pseudocode standards.
Utilise programming structures to develop a program.
Step 1: Make It
This simple compass will show you which way is North.
Your micro:bit has a compass sensor called a magnetometer that measures magnetic fields. It can sense the Earth’s magnetic field and so you can use it as a compass.
When you first use the micro:bit compass you have to calibrate it. A little game appears on the screen where you have to tilt the micro:bit to light up every LED, then you’re ready to go.
The program uses an infinite (forever) loop to keep taking compass readings and it stores them in a variable called ‘bearing’. It then uses selection: an if… else statement to show N for North on the LED display if the bearing is greater (>) than 315 degrees or less than (<) 45. This means that it will show you where North is as long as your micro:bit is pointing in roughly the right direction.
In pairs, work through the worksheet attached to breakdown the program.
Use the description above to find your answers.
Pseudocode Tip - the pseudocode standard for compass is:
COMPASS ______
So get the bearing of the compass it would be.
COMPASS bearing
Step 2: Code It
Use the reference list in micro:bit classroom.
There is a compass section which examples how to use the functions built into the micro:bit.
Step 3: Improve It
Increase Accuracy
Make the compass more accurate by reducing the range of bearings: make the number 45 smaller and 315 bigger.
Show East, West and South
Add other points of the compass to show when the micro:bit is pointing East, West and South.
Add an Audio Indicator
Add sound so it makes a noise when pointing North so someone who is visually impaired can use the compass.