# Write your code here :-)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""This example lights up all the NeoPixel LEDs red."""
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, duty_cycle=2 ** 15, frequency=50)

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

cp.pixels.brightness = 5

while True:
    # print((cp.light,))
    # print((cp.sound_level,))

    if cp.button_a:
        cp.pixels.fill((252, 3, 173))
        for angle in range(0, 180, 5):  # 0 - 180 degrees, 5 degrees at a time.
            my_servo.angle = angle
            time.sleep(0.05)
        for angle in range(180, 0, -5):
            my_servo.angle = angle
            time.sleep(0.08)
            cp.play_tone(262, 1)
            cp.play_tone(294, 1)

    if cp.light > 200:
        cp.pixels[2] = (0, 255, 0)
        for angle in range(0, 90, 5):  # 0 - 180 degrees, 5 degrees at a time.
            my_servo.angle = angle
            time.sleep(0.05)
        for angle in range(90, 0, -5):
            my_servo.angle = angle
            time.sleep(0.08)

    if cp.button_b:
        cp.pixels.fill((235, 128, 52))
        for angle in range(0, 90, 5):  # 0 - 180 degrees, 5 degrees at a time.
            my_servo.angle = angle
            time.sleep(0.05)
        for angle in range(90, 0, -5):
            my_servo.angle = angle
            time.sleep(0.08)
            cp.play_tone(250, 2)
            cp.play_tone(272, 2)





