Skip to content

Commit 86b67e4

Browse files
authored
Merge pull request #836 from kattni/cpb-cpx-drum-machine-update
Update drum machine for CPB
2 parents 9bfbf7b + 11e8de6 commit 86b67e4

2 files changed

Lines changed: 54 additions & 44 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Circuit Playground 808 Drum machine
2+
import time
3+
import board
4+
import touchio
5+
import digitalio
6+
7+
try:
8+
from audiocore import WaveFile
9+
except ImportError:
10+
from audioio import WaveFile
11+
12+
try:
13+
from audioio import AudioOut
14+
except ImportError:
15+
try:
16+
from audiopwmio import PWMAudioOut as AudioOut
17+
except ImportError:
18+
pass # not always supported by every board!
19+
20+
bpm = 120 # Beats per minute, change this to suit your tempo
21+
22+
# Enable the speaker
23+
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
24+
speaker_enable.direction = digitalio.Direction.OUTPUT
25+
speaker_enable.value = True
26+
27+
# Make the input capacitive touchpads
28+
capPins = (board.A1, board.A2, board.A3, board.A4, board.A5,
29+
board.A6, board.TX)
30+
31+
touchPad = []
32+
for i in range(7):
33+
touchPad.append(touchio.TouchIn(capPins[i]))
34+
35+
# The seven files assigned to the touchpads
36+
audiofiles = ["bd_tek.wav", "elec_hi_snare.wav", "elec_cymbal.wav",
37+
"elec_blip2.wav", "bd_zome.wav", "bass_hit_c.wav",
38+
"drum_cowbell.wav"]
39+
40+
audio = AudioOut(board.SPEAKER)
41+
42+
43+
def play_file(filename):
44+
print("playing file " + filename)
45+
file = open(filename, "rb")
46+
wave = WaveFile(file)
47+
audio.play(wave)
48+
time.sleep(bpm / 960) # Sixteenth note delay
49+
50+
51+
while True:
52+
for i in range(7):
53+
if touchPad[i].value:
54+
play_file(audiofiles[i])

Introducing_CircuitPlaygroundExpress/Playground_808.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)