Skip to content

Commit 10e6555

Browse files
committed
CPX soundbox
Adding code for CPX soundbox
1 parent 5218936 commit 10e6555

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

CPX_Sound_Box/code.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import board
2+
from digitalio import DigitalInOut, Direction, Pull
3+
import audioio
4+
import neopixel
5+
import time
6+
7+
filename = "electrons.wav"
8+
9+
# What pad our button is connected to:
10+
button = DigitalInOut(board.A4)
11+
button.direction = Direction.INPUT
12+
button.pull = Pull.UP
13+
14+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)
15+
16+
# NeoPixel Animation
17+
def simpleCircle(wait):
18+
PURPLE = (255, 0, 255)
19+
BLACK = (0, 0, 0)
20+
CYAN = (0, 255, 255)
21+
ORANGE = (255, 255, 0)
22+
23+
for i in range(len(pixels)):
24+
pixels[i] = PURPLE
25+
time.sleep(wait)
26+
for i in range(len(pixels)):
27+
pixels[i] = CYAN
28+
time.sleep(wait)
29+
for i in range(len(pixels)):
30+
pixels[i] = ORANGE
31+
time.sleep(wait)
32+
for i in range(len(pixels)):
33+
pixels[i] = BLACK
34+
time.sleep(wait)
35+
36+
# Audio Stuff
37+
def play_file(filename):
38+
print("Playing File" + filename)
39+
wave_file = open(filename, "rb")
40+
with audioio.WaveFile(wave_file) as wave:
41+
with audioio.AudioOut(board.A0) as audio:
42+
audio.play(wave)
43+
while audio.playing:
44+
pass
45+
simpleCircle(.02)
46+
print("finished")
47+
48+
while True:
49+
if not button.value:
50+
play_file(filename)

CPX_Sound_Box/electrons.wav

82.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)