Skip to content

Instantly share code, notes, and snippets.

@kwalseth
Created March 26, 2020 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwalseth/3a26fe6321de13e04f5f47e0b8507061 to your computer and use it in GitHub Desktop.
Save kwalseth/3a26fe6321de13e04f5f47e0b8507061 to your computer and use it in GitHub Desktop.
firetruck lights
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", "siren.wav", "firetruck.wav"]
def fireeffect():
pixel1[random.randrange(45)] = (255, 0, 0)
pixel1[random.randrange(45)] = color2
pixel1[random.randrange(45)] = color2
pixel1[random.randrange(45)] = color2
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.8)
pixel1 = neopixel.NeoPixel(board.A1, 45, 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
time_started = 0
while True:
now = time.monotonic()
if touch.value:
play_file(audiofiles[1])
time_started = now
if now - time_started < 12:
fireeffect()
else:
pixel1.fill((0, 0, 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment