
from adafruit_circuitplayground import cp
from adafruit_motor import servo
import time
import board
import pwmio



alarm = 11
shake = 10
switchC = True

# create a PWMOut object on Pin A2.
pwm = pwmio.PWMOut(board.A2, frequency=50)

# Create a servo object, my_servo.
my_servo = servo.ContinuousServo(pwm)

my_servo.throttle = 0.04


while True:



    if alarm == 11:
        cp.pixels.fill((0, 0, 50))
    else:
        cp.pixels[alarm] = (0, 50, 0)
        alarm += 1
        time.sleep(1.0)

    if alarm == 10:
        cp.play_file("alert.wav")
        alarm = 11

    if cp.shake():
        shake = 0
        if shake == 10:
            shake = 10
        else:
            while shake < 10:
                if switchC:
                    cp.pixels[0] = (0, 50, 0)
                    cp.pixels[1] = (0, 0, 50)
                    cp.pixels[2] = (0, 50, 0)
                    cp.pixels[3] = (0, 0, 50)
                    cp.pixels[4] = (0, 50, 0)
                    cp.pixels[5] = (0, 0, 50)
                    cp.pixels[6] = (0, 50, 0)
                    cp.pixels[7] = (0, 0, 50)
                    cp.pixels[8] = (0, 50, 0)
                    cp.pixels[9] = (0, 0, 50)
                    time.sleep(0.5)
                    switchC = False
                    shake += 1
                else:
                    cp.pixels[1] = (0, 50, 0)
                    cp.pixels[0] = (0, 0, 50)
                    cp.pixels[3] = (0, 50, 0)
                    cp.pixels[2] = (0, 0, 50)
                    cp.pixels[5] = (0, 50, 0)
                    cp.pixels[4] = (0, 0, 50)
                    cp.pixels[7] = (0, 50, 0)
                    cp.pixels[6] = (0, 0, 50)
                    cp.pixels[9] = (0, 50, 0)
                    cp.pixels[8] = (0, 0, 50)
                    time.sleep(0.5)
                    switchC = True
                    shake += 1



    if cp.button_a:
        alarm = 0


