# sensing touch with the MPR121
import board
import adafruit_mpr121
import time
import neopixel
import adafruit_led_animation
from adafruit_led_animation.animation.pulse import Pulse
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)
#pulse. the period is how long it takes for the pulse to complete
#sets up led strip
strip_pin= board.A1
strip_num_of_lights = 20
strip = neopixel.NeoPixel(strip_pin, strip_num_of_lights)
strip.fill(BLACK)

def pulse_orange():
    strip.fill(ORANGE)
    for index in range(0,10):
            print(index)
            strip.brightness = index/10
            time.sleep(.1)
    for index in range(9,-1,-1):
            print(index)
            strip.brightness = index/10
            time.sleep(.1)

def pulse_white():
    strip.fill(WHITE)
    for index in range(0,10):
            print(index)
            strip.brightness = index/10
            time.sleep(.1)
    for index in range(9,-1,-1):
            print(index)
            strip.brightness = index/10
            time.sleep(.1)


i2c = board.I2C()
touchpad = adafruit_mpr121.MPR121(i2c)

animation_for_orange = False
animation_for_white = False

while True:
    #checking index 0 to 11 to see if the touchpad has been touched
while True:
    for i in range (12):
        if touchpad[8].value:
            animation_for_orange = True
        if touchpad[7].value:
            animation_for_orange = False
            strip.fill(BLACK)
        if animation_for_orange:
            pulse_orange()

        if touchpad[3].value:
            animation_for_white = True
        if touchpad[4].value:
            animation_for_white = False
            strip.fill(BLACK)
        if animation_for_white:
            pulse_white()
