# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#  from adafruit_motor import servo
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""CircuitPython Essentials Servo standard servo example"""

import board
import pwmio
from adafruit_motor import servo
from adafruit_circuitplayground.express import cpx
import time

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

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

while True:
    if cpx.button_a:
        print("Button A pressed!")
        for angle in range(50, 180, 5):
            my_servo.angle = angle
            time.sleep(.5)
    else:
        my_servo.angle = 0

    if cpx.button_b:
        print("Button B pressed!")
        for angle in range(0, 0, 0):
            my_servo.angle = angle
            time.sleep(100000000)
    else:
        cpx.pixels[9] = (0, 0, 0)

    if cpx.switch:
        for angle in range(-50, -180, 5):
            my_servo.angle = angle
    else:
        cpx.pixels[4] = (0, 0, 0)
        cpx.pixels[5] = (0, 0, 30)
# Write your code here :-)
