# Assistive Project
import board, neopixel, pwmio, digitalio, time, random, mount_sd
from audiopwmio import PWMAudioOut as AudioOut
from audiocore import WaveFile
from adafruit_motor import servo
from adafruit_debouncer import Button

maroon = (128,0,0)
gold = (255,100,0)
black = (0,0,0)

colors = [maroon, gold]

strip = neopixel.NeoPixel(board.GP3, 30, brightness = 0.1, auto_write=True)

pwm = pwmio.PWMOut(board.GP14, frequency=50)
servo_1 = servo.Servo(pwm, min_pulse = 750, max_pulse = 2250)
servo_1.angle = 0

button = digitalio.DigitalInOut(board.GP18)
button.switch_to_input(pull=digitalio.Pull.UP)

audio = AudioOut(board.GP16)

def moving_object():
    for i in range(0,150):
        servo_1.angle = i
        time.sleep(0.01)
        strip.fill(gold)
    time.sleep(0.001)
    for i in range(150,0,-1):
        servo_1.angle = i
        time.sleep(0.01)
        strip.fill(maroon)
    strip.fill(black)
    time.sleep(0.001)

path = "/sd/assistive/"

def play_sound(filename):
    with open(path + filename, "rb") as wave_file:
        wave = WaveFile(wave_file)
        audio.play(wave)
        while audio.playing:
            moving_object()

strip.fill(black)

while True:
    if button.value:
        pass
    else:
        print("Button Pressed")
        play_sound("forboston.wav")
    time.sleep(0.5)

