Last active
November 30, 2018 05:59
-
-
Save caitlinsdad/8cc9455ad402b680903020d65097b7d1 to your computer and use it in GitHub Desktop.
Cat Safety Sign CircuitPython
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 time | |
import board | |
import neopixel | |
import touchio | |
import audioio | |
from digitalio import DigitalInOut, Direction | |
import simpleio | |
touch2 = touchio.TouchIn(board.A2) | |
touch3 = touchio.TouchIn(board.A3) | |
touch4 = touchio.TouchIn(board.A4) | |
touch5 = touchio.TouchIn(board.A5) | |
touch6 = touchio.TouchIn(board.A6) | |
touch7 = touchio.TouchIn(board.A7) | |
# enable the speaker | |
spkrenable = DigitalInOut(board.SPEAKER_ENABLE) | |
spkrenable.direction = Direction.OUTPUT | |
spkrenable.value = True | |
# The .wav sound files | |
audiofiles = ["CatEvil.wav", "drum_cowbell.wav"] | |
a = audioio.AudioOut(board.A0) | |
bling = .1 | |
pixelpin = board.A1 | |
pixels = neopixel.NeoPixel(pixelpin, 2, brightness=bling) | |
pixelpinX = board.NEOPIXEL | |
pixelsX = neopixel.NeoPixel(pixelpinX, 10, brightness=bling) | |
pixels.fill((50, 50, 50)) | |
pixels.show() | |
time.sleep(0.1) | |
pixels.fill((0, 0, 0)) | |
pixels.show() | |
def play_file(filename): | |
print("playing file " + filename) | |
f = open(filename, "rb") | |
wave = audioio.WaveFile(f) | |
a.play(wave) | |
while True: | |
pixels.fill((50, 50, 50)) | |
pixelsX.fill((50, 50, 50)) | |
pixels.show() | |
if touch2.value: | |
print("Touched TAIL") | |
pixels.fill((100, 100, 0)) | |
time.sleep(0.1) | |
if touch3.value: | |
print("Touched NECK") | |
pixels.fill((0, 100, 0)) | |
time.sleep(0.1) | |
if touch4.value: | |
print("Touched BACK") | |
play_file(audiofiles[1]) | |
pixels.fill((0, 255, 0)) | |
time.sleep(0.1) | |
if touch5.value: | |
print("Touched BELLY") | |
play_file(audiofiles[0]) | |
pixels.fill((255, 0, 0)) | |
pixelsX.fill((255, 0, 0)) | |
time.sleep(0.1) | |
pixels.fill((0, 0, 0)) | |
pixels.fill((0, 0, 0)) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment