#NIGHTLIGHT Project

import board, time, neopixel
from analogio import AnalogIn

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)

colors = [RED, BLUE, ORANGE, YELLOW, GREEN, JADE, PINK, INDIGO, VIOLET, PURPLE, BLACK]

strip_pin = board.A1
strip_num_of_lights = 30
strip = neopixel.NeoPixel(strip_pin, strip_num_of_lights, brightness = 1)

potentiometer = AnalogIn(board.A3)

def pulse(color):
    while True:
        strip.fill(color)
        for i in range(30,101):
            strip.brightness = i/100
            time.sleep(0.02)
        for i in range(100,30,-1):
            strip.brightness = i/100
            time.sleep (0.02)
        break


def color(potentiometer_value):
    if potentiometer.value <= 5434:
        strip.fill(RED)
        pulse(RED)
    elif potentiometer.value <= 10868:
        strip.fill(BLUE)
        pulse(BLUE)
    elif potentiometer.value <= 16302:
        strip.fill(ORANGE)
        pulse(ORANGE)
    elif potentiometer.value <= 21736:
        strip.fill(YELLOW)
        pulse(YELLOW)
    elif potentiometer.value <= 27170:
        strip.fill(GREEN)
        pulse(GREEN)
    elif potentiometer.value <= 32604:
        strip.fill(JADE)
        pulse(JADE)
    elif potentiometer.value <= 38038:
        strip.fill(PINK)
        pulse(PINK)
    elif potentiometer.value <= 43472:
        strip.fill(INDIGO)
        pulse(INDIGO)
    elif potentiometer.value <= 48906:
        strip.fill(CYAN)
        pulse(CYAN)
    elif potentiometer.value <= 54340:
        strip.fill(PURPLE)
        pulse(PURPLE)
    elif potentiometer.value <= 59774:
        strip.fill(WHITE)
        pulse(WHITE)
    else:
        strip.fill(BLACK)

for i in range(1000000):
    print(potentiometer.value)
    color(potentiometer.value)
