# Compass treasure map: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/compass-treasure-map
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# Compass treasure map: follow a route of bearings. Turn until you see the tick, walk, then press A for the next one.
from microbit import *

route = [45, 180, 270, 0]
leg = 0

while True:
    if button_a.was_pressed():
        leg = leg + 1
    if button_b.was_pressed():
        leg = 0
    if leg >= len(route):
        display.show(Image.DIAMOND)
    else:
        diff = (route[leg] - compass.heading() + 360) % 360
        if diff < 20 or diff > 340:
            display.show(Image.YES)
        elif diff < 180:
            display.show(Image.ARROW_E)
        else:
            display.show(Image.ARROW_W)
    sleep(200)
