# 30-second fitness challenge: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/fitness-challenge
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# 30-second fitness challenge: press A, count down, then jump. The count shows after 30 seconds.
from microbit import *
import math

while True:
    if button_a.was_pressed():
        for n in (3, 2, 1):
            display.show(n)
            sleep(500)
        display.show(Image.YES)
        jumps = 0
        end = running_time() + 30000
        while running_time() < end:
            x, y, z = accelerometer.get_values()
            if math.sqrt(x * x + y * y + z * z) > 2000:
                jumps = jumps + 1
                sleep(300)
            sleep(10)
        display.scroll(jumps)
    sleep(50)
