import board, time, pwmio, neopixel
from analogio import AnalogIn
import adafruit_lis3dh, busio ,touchio
import digitalio
import busio, adafruit_lis3dh
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.colorcycle import ColorCycle



from adafruit_led_animation.color import RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, \
   BLUE, PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER, OLD_LACE, WHITE, BLACK

colors = [RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, BLUE, PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER, OLD_LACE, WHITE, BLACK]

potentiometer = AnalogIn(board.A3)
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)

accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c,address=0x19)
accelerometer.range = adafruit_lis3dh.RANGE_4_G



strip = neopixel.NeoPixel(board.A1,30,brightness=potentiometer.value)
pulse_strip = Pulse(strip,speed=0.1,color=AMBER,period=5)
chase_strip= Chase(strip,speed=0.1,color=WHITE,size=3,spacing=6)
rainbow_strip = Rainbow(strip,speed=0.05,period=2)
comet_strip = Comet(strip, speed=0.005,color = PURPLE,tail_length=int(30/4),bounce=True)
colorcycle_strip = ColorCycle(strip, speed=.1,colors=colors)



strip.fill(BLACK)
strip.show()


def star_power():
    strip.fill(BLUE)
    strip.show()
    time.sleep(10)
    strip.fill(BLACK)
    strip.show()

while True:
    value = potentiometer.value
    print(value)
    if accelerometer.shake(shake_threshold=15):
       star_power()
    elif value < 1000:
        chase_strip.animate()
    elif (value > 1000 and value < 15000):
        pulse_strip.animate()
    elif (value > 15000 and value < 30000):
        comet_strip.animate()
    elif value > 50000:
        rainbow_strip.animate()



