# # Write your code here :-)
#Bridget Falkenhayn Art Project


import board
import digitalio, time, neopixel, adafruit_mpr121
import adafruit_led_animation
from rainbowio import colorwheel
from adafruit_debouncer import Button

from analogio import AnalogIn
from adafruit_led_animation.animation.colorcycle import ColorCycle



from adafruit_led_animation.color import (
    AMBER,  # (255, 100, 0)
    AQUA,  # (50, 255, 255)
    BLACK,  # OFF (0, 0, 0)
    BLUE,  # (0, 0, 255)
    CYAN,  # (0, 255, 255)
    GOLD,  # (255, 222, 30)
    GREEN,  # (0, 255, 0)
    JADE,  # (0, 255, 40)
    MAGENTA,  # (255, 0, 20)
    OLD_LACE,  # (253, 245, 230)
    ORANGE,  # (255, 40, 0)
    PINK,  # (242, 90, 255)
    PURPLE,  # (180, 0, 255)
    RED,  # (255, 0, 0)
    TEAL,  # (0, 255, 120)
    WHITE,  # (255, 255, 255)
    YELLOW,  # (255, 150, 0)
    RAINBOW,  # a list of colors to cycle through
    # RAINBOW is RED, ORANGE, YELLOW, GREEN, BLUE, and PURPLE ((255, 0, 0), (255, 40, 0), (255, 150, 0), (0, 255, 0), (0, 0, 255), (180, 0, 255))
)

import board, digitalio
from audiopwmio import PWMAudioOut as AudioOut
from audiocore import WaveFile

# set up the speaker
speaker = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
speaker.direction = digitalio.Direction.OUTPUT
speaker.value = True
audio = AudioOut(board.SPEAKER)

def party():
    strip[0] = BLUE
    strip[2] = RED
    strip[4] = GREEN
    strip[9] = PURPLE
    strip[11] = BLUE
    strip[13] = RED
    strip[15] = GREEN
    strip[17] = PURPLE
    strip[19] = BLUE
    time.sleep(0.2)
    strip[0] = RED
    strip[2] = GREEN
    strip[4] = PURPLE
    strip[9] = BLUE
    strip[11] = RED
    strip[13] = GREEN
    strip[15] = PURPLE
    strip[17] = BLUE
    strip[19] = RED
    time.sleep(0.2)
    strip[0] = GREEN
    strip[2] = PURPLE
    strip[4] = RED
    strip[9] = GREEN
    strip[11] = BLUE
    strip[13] = GREEN
    strip[15] = PURPLE
    strip[17] = RED
    strip[19] = GREEN
    time.sleep(0.2)
    strip[0] = BLUE
    strip[2] = RED
    strip[4] = GREEN
    strip[9] = PURPLE
    strip[11] = BLUE
    strip[13] = RED
    strip[15] = GREEN
    strip[17] = PURPLE
    strip[19] = BLUE






button_A_input = digitalio.DigitalInOut(board.A4)
button_B_input = digitalio.DigitalInOut(board.A5)


button_A_input.switch_to_input(digitalio.Pull.UP) # Note: Pull.UP for external buttons
button_B_input.switch_to_input(digitalio.Pull.UP) # Note: Pull.UP for external buttons



button_A = Button(button_A_input, value_when_pressed = True)
button_B = Button(button_B_input, value_when_pressed = True)


potentiometer = AnalogIn(board.A6)

strip_num_of_lights = 20
strip = neopixel.NeoPixel(board.A1, strip_num_of_lights)

party_mode = False
warm_light = True


while True:
    button_A.update()
    button_B.update()
    if warm_light:
        strip.fill(((228,112,37)))
        brightness_level = (potentiometer.value/655335*10)

        #print(potentiometer.value)
        strip.brightness = brightness_level

    if party_mode:
        strip.brightness = 100
        party()
    if button_A.pressed:
        print("button A Pressed")
        warm_light = True
        party_mode = False
    if button_B.pressed:
        print("Button B Pressed")
        warm_light = False
        party_mode = True





