# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""CircuitPython Essentials Servo continuous rotation servo example"""
import time
import board
import pwmio
from adafruit_motor import servo
from adafruit_circuitplayground import cp


# create a PWMOut object on Pin A2.
pwm = pwmio.PWMOut(board.A2, frequency=50)

# Create a servo object, my_servo.
my_servo = servo.ContinuousServo(pwm)

while True:
        if cp.button_a:
            my_servo.throttle = 0.1
            cp.pixels.fill((0, 0, 0))
            time.sleep(0.1)
            my_servo.throttle = 0.0

        if cp.button_b:
            my_servo.throttle = -0.1
            cp.pixels.fill((255, 255, 255))
            time.sleep(0.1)
            my_servo.throttle = 0.0
