This lesson is a spin off of John Park's Drum Machine.
We can use the capacitive touch pads on the Circuit Playground Express as triggers and small .wav files for our drum sounds!
Until now, we needed to code in CircuitPython to play sound files. Now with EduBlocks, all we need to do is drag a couple of blocks and we're good to go!
First, download the .zip file below, which contains all of the drum samples we'll be using. Save the file to your desktop or somewhere else easy to find, and then unzip it.
You can plug in your Circuit Playground Express, and then drag the drum files onto it. It shows up as the CIRCUITPY drive.
|
|
|
Download the main.py file and drag to the CPX.
Try it out!
Sounds should be triggering when each coin is touched or held!
If you want to use your own sound files, you can! Record, sample, remix, or simply download files from a sound file sight, such as freesample.org. Then, to make sure you have the files converted to the proper specifications, check out this guide here that'll show you how! Spoiler alert: you'll need to make a small, 22Khz (or lower), 16 bit PCM, mono .wav file!
Want to listen to your Drum Machine at body movin' volumes? No problem! Hook up an 1/8" or 1/4" phono output to the GND and A0 pads, then plug in to an amp or speaker! I tried it on a small speaker with an aux input and it sounded great!
Here are the code files if you want to upload directly to EduBlocks or the CPX.
touch1 = None touch2 = None touch3 = None touch4 = None touch5 = None touch6 = None touch7 = None BPM = None import time import board import touchio from digitalio import * from adafruit_circuitplayground.express import cpx BPM = .125 touch1 = touchio.TouchIn(board.A1) 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) while True: if touch1.value: cpx.play_file("bd_tek.wav") time.sleep(BPM) elif touch2.value: cpx.play_file("elec_hi_snare.wav") time.sleep(BPM) elif touch3.value: cpx.play_file("elec_cymbal.wav") time.sleep(BPM) elif touch4.value: cpx.play_file("elec_blip2.wav") time.sleep(BPM) elif touch5.value: cpx.play_file("bd_tek.wav") time.sleep(BPM) elif touch6.value: cpx.play_file("bass_hit_c.wav") time.sleep(BPM) elif touch7.value: cpx.play_file("drum_cowbell.wav") time.sleep(BPM)