Week 21. Jan 22.25 2019 - michelle-qin/Portfolio GitHub Wiki
Today, I followed my favorite tutorial yet for the adafruit playground: Playground Drum Machine The playground has capacitive touch pads all around its perimeter - i.e. whenever a user touches a pad, it can detect that it was touched. For this particular tutorial, different drum sounds were associated with different pins, allowing the user to conduct a musical through their very thumbs (more exciting in person)
As with every tutorial, I try to understand the code as best as I can. This time, there were some new Python syntax that I learned after speaking with a mentor. See my notes below:
import time
import audioio
import board
import touchio
from digitalio import DigitalInOut, Direction
bpm = 120 # beats per minute, change this to suit your tempo
**enable the speaker**
spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = Direction.OUTPUT
spkrenable.value = True
**make the input cap sense pads**
capPins = (board.A1, board.A2, board.A3, board.A4, board.A5,
board.A6, board.A7)
touchPad = [] **this creates an empty array allowing any amount of objects to be appended in it (which is done in the following 2 lines)**
for i in range(7):
touchPad.append(touchio.TouchIn(capPins[i])) **initialized 7 pins to be input pins**
**The seven files assigned to the touchpads**
audiofiles = ["bd_tek.wav", "elec_hi_snare.wav", "elec_cymbal.wav",
"elec_blip2.wav", "bd_zome.wav", "bass_hit_c.wav",
"drum_cowbell.wav"]
a = audioio.AudioOut(board.A0)
def play_file(filename):
print("playing file " + filename)
f = open(filename, "rb") **"rb" is a Python syntax for opening & reading a file and binary code**
wave = audioio.WaveFile(f)
a.play(wave)
time.sleep(bpm / 960) # sixteenthNote delay
while True:
`for i in range(7):`
`if touchPad[i].value:`
`play_file(audiofiles[i])`
This week, I received the product that will be implemented in the Ball Wall. It is composed of 3 different Adafruit boards (M4 Express Feather (3857), Servo (2928), and Stepper (2927)). I've played with it a little, connecting it to my tablet and downloading required files. I checked into the tutorial for the Feather board and it's quite similar (if not exactly the same) as the tutorial I was following for the playground. I'm still using CircuitPython to program the board.
Since I've already caught up with most of the basics from the playground tutorial, I'm looking into how I can control a servo motor with this board. This is still a work in progress, so more to come later!