-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathpidaydrummachine.py
40 lines (30 loc) · 1.13 KB
/
pidaydrummachine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# pidaydrummachine.py - Pi Day Drum Machine
# 14 Mar 2021 - @todbot / Tod Kurt
# samples from: https://freesound.org/people/BaDoink/packs/30682/
#
import time
import board
import keypad
import audiocore
import audiomixer
from audiopwmio import PWMAudioOut as AudioOut
time.sleep(3) # wait a bit to reduce noise from CIRCUITPY access
wav_files = (
"wav/544413_punch_22k16b.wav",
"wav/544682_snare_22k16b.wav",
"wav/544684_dubhat1_22k16b.wav",
"wav/544694_toggle_22k16b.wav",
"wav/544587_splash1a_22k16b.wav",
)
# what keys to use as our drum machine
keys = keypad.Keys((board.GP16, board.GP17, board.GP18, board.GP19, board.GP20),
value_when_pressed=False, pull=True)
audio = AudioOut(board.GP15)
mixer = audiomixer.Mixer(voice_count=len(wav_files), sample_rate=22050, channel_count=1,
bits_per_sample=16, samples_signed=True)
audio.play(mixer) # attach mixer to audio playback, play with mixer.voice[n].play()
while True:
event = keys.events.get()
if event and event.pressed:
n = event.key_number
mixer.voice[n].play( audiocore.WaveFile(open(wav_files[n],"rb")) )