/ Milk_Jug_Glow_Skull / code.py
code.py
1 # SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 import board 7 import digitalio 8 import audioio 9 import audiocore 10 import neopixel 11 12 # user variables 13 pix_rate = 0.03 # Increase the number to slow down the color chase 14 blink_times = 2 # number of times the eyes blink between color chases 15 blink_speed = 0.1 # speed of the blinks, lower numbers are faster 16 rest_time = 3 # time between color changes e.g. '3' = 3 sec, '300'= 5 mins. 17 18 # setup 19 NEOPIXEL_PIN = board.EXTERNAL_NEOPIXEL 20 NUM_PIXELS = 30 21 pixels = neopixel.NeoPixel(NEOPIXEL_PIN, NUM_PIXELS) 22 23 24 led = digitalio.DigitalInOut(board.D13) 25 led.direction = digitalio.Direction.OUTPUT 26 led.value = True 27 time.sleep(0.5) 28 29 ORANGE = (255, 30, 0) 30 PURPLE = (200, 0, 255) 31 RED = (255, 0, 0) 32 GREEN = (0, 255, 0) 33 BLACK = (0, 0, 0) 34 35 COLORS = [ORANGE, PURPLE, RED, GREEN, ORANGE, PURPLE, RED] 36 37 pixels.fill(ORANGE) 38 pixels.show() 39 40 def color_chase(color, wait): 41 for i in range(NUM_PIXELS): 42 pixels[i] = color 43 time.sleep(wait) 44 pixels.show() 45 46 47 def blink(times, speed): 48 for _ in range(times): 49 led.value = False 50 time.sleep(speed) 51 led.value = True 52 time.sleep(speed) 53 54 def play_waves(file_num): 55 wave_file = open(wave_files[file_num], "rb") # open a wav file 56 wave = audiocore.WaveFile(wave_file) 57 audio.play(wave) # play the wave file 58 while audio.playing: # allow the wav to finish playing 59 pass 60 wave_file.close() # close the wav file 61 62 wave_files = ["alex_deepgrowl1.wav", "alex-highgrowl1.wav", "alex-squeal1.wav", 63 "toni-deepgrowl.wav", "toni-highgrowl2.wav","toni-pigsqueal.wav", 64 "toni-pitchedscream2.wav"] 65 audio = audioio.AudioOut(board.A0) 66 67 while True: 68 for k in range(len(wave_files)): 69 blink(blink_times, blink_speed) 70 color_chase(COLORS[k], pix_rate) 71 play_waves(k) 72 time.sleep(rest_time)