#Maximilian Kaufmann
#Your Electric Capacitive Touch

import board
import neopixel
import time
import digitalio
import touchio

#setup board
pixels_pin=board.NEOPIXEL
pixels_num_of_lights=10
pixels=neopixel.NeoPixel(pixels_pin, pixels_num_of_lights,brightness = 0.5, auto_write= True)

#setup speaker
from audiopwmio import PWMAudioOut as AudioOut
from audiocore import WaveFile
#configure
speaker = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
speaker.direction = digitalio.Direction.OUTPUT
speaker.value = True
audio = AudioOut(board.SPEAKER)
#path where sound file can be found
path="game_sounds/"

def playfile(soundfile):
    with open(path + soundfile,"rb") as wave_file:
        wave=WaveFile(wave_file)
        audio.play(wave)
        while audio.playing:
            pass

playfile("on.wav")


pad=[board.A1,board.A2]
touchpad=[]
sounds=["jack1.wav","cheer.wav"]
for i in range(len(pad)):
    touchpad.append(touchio.TouchIn(pad[i]))

while True:
    touched=False
    for i in range(len(touchpad)):
        if touchpad[i].value:
            playfile(sounds[i])
            touched=True
