Check out our micro:bit in the classroom video if you'd like to see how micro:bit integrates into classrooms, years 7-12.
After a quick review of the hardware, we'll fire up a micro:bit and write our first program. All you'll need for this tutorial is a micro:bit and a micro-USB lead. There's no software to download because we write code from within the web browser!
For this tutorial we'll look at the graphical/javascript editor for micro:bit. Head over to the micro:bit code menu and run the PXT editor.
Code for this tutorial
If you want a copy of the compass script, you can copy-and-paste the following into the javascript editor. Once the code is pasted in, you can change back to the Blocks editor if you like!
let heading = 0
basic.forever(() => {
heading = input.compassHeading()
if (heading <= 45) {
basic.showString("N")
} else if (heading <= 135) {
basic.showString("E")
} else if (heading <= 225) {
basic.showString("S")
} else if (heading <= 315) {
basic.showString("W")
} else {
basic.showString("N")
}
})
If you want to roll-back your micro:bit to the default demo program, you can download the attached .hex file.
Refrences
The compass program for this tutorial was sourced from the BBC: Compass lesson.


