---
description: Micro:bit and battery pack
---

# Program a Compass

We need the micro:bit  to  be contstantly reading the direction and updating what we see on the screen. To do that we need the  computer to convert degrees into the compass heading input.

```
forever
    set degrees = compass heading
```

![https://makecode.microbit.org/projects/compass](https://2507214486-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LpUPSf3tCxHePJxNjfg%2F-LswxnSu3SE3_oZQh4HL%2F-LswyOa_mNYLQlwK0_1g%2Fimage.png?alt=media\&token=c7d22157-53c9-44d5-9ac4-d106fe56f298)

So what is north?? Well if we are facing < 45 degrees  OR more than 315 degrees  then we are "mostly"  heading north and we  want an N to be displayed on the LED screen.

```
if degress < 45 OR  > 315
   show  "N" 
```

### Now we need to duplicate this for the other directions:

* [ ] East is  less  than 135 and Display an E
* [ ] South is  less than 225 Display S
* [ ] If NONE of these are True then we must  be point West and Display W
  * [ ] If, else If, else If,  else

Now attach your battery back and do some walking to see if this works!

This assignment is based on a project found at [https://makecode.microbit.org/projects/compass](https://makecode.microbit.org/projects/compass)
