# Making a point

## An empty gesture

### Learn It

• We looked at the accelerometer in the previous lesson. This can also be used to pick up data about the movement of the Micro:bit, in the form of gestures.
• We can write programs to take advantage of these; my favourites are `face up`, `face down` and `shake`. Let's try using one now.
• Try this:
```from microbit import *

while True:
gesture = accelerometer.current_gesture()
if gesture == "shake":
display.show(Image.HAPPY)
sleep(2000)
else:
display.show(Image.ASLEEP)
```

## Compass

### Learn It

• The Micro:bit also has a built-in electronic compass.
• It reads the Earth's magnetic field, and uses this to give a bearing on which way the Micro:bit is facing, from 0 to 359 degrees. 0 degrees is North, 90 is East, 180 is South and so on.
• The compass will need calibrating first so that it knows which way to point.
• Once done, you can either show the bearing number on the screen, or be a little more ambitious and use an LED on the display to point out the direction.
• Let's start simple. Our pseudocode for this is:
```CALIBRATE COMPASS

WHILE True
END WHILE
```
• Note: You can get more detail on the capabilities of the compass by looking through the documentation for MicroPython here.

### Code It

• Let's write some code now…
```from microbit import *
compass.calibrate()

while True:
```
• After you complete the calibration sequence (tilt and roll the Micro:bit around in a circle), you'll get readings showing which way is North.
• NOTE: If you're using this inside, nearby metal objects and equipment using magnets (e.g. speakers, motors) can affect the accurate of the compass quite significantly).

### Learn It

• Using variables and `If` statements, we can make something a little more like a compass.
• I'd like to make the Micro:bit show a letter to indicate direction as I rotate the Micro:bit round. It won't be super-accurate, but it'll give an indication for the user.
• From 46 to 135 degrees, we'll show E.
• From 136 to 225 degrees, we'll show S.
• From 226 to 315 degrees, we'll show W.
• Finally, let's say that for a bearing of less than 46 or greater than 316 degrees, the Micro:bit should say N.
• Our pseudocode will need to be something like this:
```CALIBRATE COMPASS

WHILE True

PRINT "N"
PRINT "E"
PRINT "S"
ELSE
PRINT "W"
END IF
END WHILE
```

### Code It

• Let's write the program…
```from microbit import *
compass.calibrate()

while True:

display.show("N")