Created
March 26, 2020 15:48
-
-
Save kwalseth/02e278e157ae16d106c55b92ea695ea8 to your computer and use it in GitHub Desktop.
Firetruck Lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
import board | |
import neopixel | |
import touchio | |
import digitalio | |
from audioio import WaveFile | |
from audioio import AudioOut | |
touch_pad = board.A3 | |
touch = touchio.TouchIn(touch_pad) | |
spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) | |
spkrenable.direction = digitalio.Direction.OUTPUT | |
spkrenable.value = True | |
audiofiles = ["rimshot.wav", "laugh.wav"] | |
def fireeffect(): | |
pixel1[random.randrange(30)] = (255, 0, 0) | |
pixel1[random.randrange(30)] = color2 | |
pixel1[random.randrange(30)] = color2 | |
pixel1[random.randrange(30)] = color2 | |
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.8) | |
pixel1 = neopixel.NeoPixel(board.A1, 30, brightness=0.8) | |
color2 = (50, 0, 0) | |
fire = 0 | |
def play_file(filename): | |
wave_file = open(filename, "rb") | |
with WaveFile(wave_file) as wave: | |
with AudioOut(board.SPEAKER) as audio: | |
audio.play(wave) | |
while audio.playing: | |
pass | |
while True: | |
if touch.value: | |
fireeffect() | |
play_file(audiofiles[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment