"""A small Maqueen robot demonstration.

Copy this file and ``maqueen.py`` to the micro:bit Python Editor, then run it
on a Maqueen Lite (V1-V4).  Positive motor speeds drive forwards; negative
speeds drive backwards.
"""

from microbit import sleep

from maqueen import Maqueen


robot = Maqueen()


def light(on):
    """Turn both of the Maqueen's front LEDs on or off."""
    robot.write_led(robot.LED_LEFT, on)
    robot.write_led(robot.LED_RIGHT, on)


def start():
    """Start driving forwards."""
    robot.motor(robot.ALL, 150)


def stop():
    """Stop both motors."""
    robot.motor_stop()


def turn_right():
    """Turn right on the spot using arcade drive."""
    robot.arcade_drive(0, 150)


def main():
    light(True)
    sleep(500)

    start()
    sleep(1500)
    stop()
    sleep(500)

    turn_right()
    sleep(700)
    stop()

    light(False)


try:
    main()
finally:
    # Make sure the robot is not left driving if the program is interrupted.
    stop()

