#Website for letters audio wav file: #https://evolution.voxeo.com/library/audio/prompts/alphabet/index.jsp

import board, time, pwmio, neopixel, touchio, random, digitalio
from audiopwmio import PWMAudioOut as AudioOut
from audiocore import WaveFile
#For the rainbow function
from rainbowio import colorwheel
#For the Sparkle function
from adafruit_led_animation.animation.sparkle import Sparkle
#Importing various colors
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))
)

INDIGO = (63, 0, 255)
VIOLET = (127, 0, 255)

#Diwali colors
colors = [RED, YELLOW, MAGENTA, BLUE, ORANGE, GREEN]

#Setup for strand
strip_pin = board.A1
strip_num_of_LEDs = 30
strip = neopixel.NeoPixel(strip_pin, strip_num_of_LEDs)

#Setup for capacitive touch
pad = [board.TX, board.A3, board.A4, board.A5, board.A6]
touchpad = []

for i in range(len(pad)):
    touchpad.append(touchio.TouchIn(pad[i]))

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

path = "sounds/"

strip.fill(BLACK)

#Turns on specific lights on the strip
def lights_on(light_color):
    strip.fill(light_color)

# play_sound function - pass in the FULL NAME of file to play
# Added additional parameters to change lists and colors depending on letter pressed
def play_sound(filename):
    with open(path + filename, "rb") as wave_file:
        wave = WaveFile(wave_file)
        audio.play(wave)
        while audio.playing:
            pass

lights_list1 = [0,1,2,3,4]
lights_list2 = [5,6,7,8,9]
lights_list3 = [10,11,12,13,14]
lights_list4 = [15,16,17,18,19]

while True:
    #Letter N
    if touchpad[0].value:
        lights_on(RED)
        play_sound("N.wav")
        time.sleep(0.5)
        strip.fill(BLACK)
    #Letter O
    if touchpad[1].value:
        lights_on(YELLOW)
        play_sound("O.wav")
        time.sleep(0.5)
        strip.fill(BLACK)
    #Letter A
    if touchpad[2].value:
        lights_on(RED)
        play_sound("A.wav")
        time.sleep(0.5)
        strip.fill(BLACK)
    #Letter H
    if touchpad[3].value:
        lights_on(GREEN)
        play_sound("H.wav")
        time.sleep(0.5)
        strip.fill(BLACK)
    #NOAH
    if touchpad[4].value:
        lights_on(WHITE)
        play_sound("Noah.wav")
        time.sleep(0.5)
        strip.fill(BLACK)
