Created
September 23, 2020 15:09
-
-
Save FoamyGuy/80774daa4f77da26acea770f2486ed84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Circuit Playground 808 Drum machine | |
import time | |
import board | |
import touchio | |
import digitalio | |
import neopixel | |
from adafruit_led_animation.animation.comet import Comet | |
from adafruit_led_animation.color import BLUE | |
try: | |
from audiocore import WaveFile | |
except ImportError: | |
from audioio import WaveFile | |
try: | |
from audioio import AudioOut | |
except ImportError: | |
try: | |
from audiopwmio import PWMAudioOut as AudioOut | |
except ImportError: | |
pass # not always supported by every board! | |
pixel_pin = board.TX | |
pixel_num = 31 | |
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.01, auto_write=False) | |
onboard_pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1.0, auto_write=True) | |
comet = Comet(pixels, speed=0.01, color=BLUE, tail_length=7, bounce=True) | |
bpm = 120 # Beats per minute, change this to suit your tempo | |
# Enable the speaker | |
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) | |
speaker_enable.direction = digitalio.Direction.OUTPUT | |
speaker_enable.value = True | |
# Make the input capacitive touchpads | |
capPins = (board.A1, board.A2, board.A3, board.A4, board.A5, | |
board.A6) | |
touchPad = [] | |
for i in range(6): | |
touchPad.append(touchio.TouchIn(capPins[i])) | |
# 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"] | |
audio = AudioOut(board.SPEAKER) | |
def play_file(filename): | |
print("playing file " + filename) | |
file = open(filename, "rb") | |
wave = WaveFile(file) | |
audio.play(wave) | |
time.sleep(bpm / 960) # Sixteenth note delay | |
while True: | |
comet.animate() | |
onboard_pixels.fill((1, 0, 0)) | |
for i in range(6): | |
if touchPad[i].value: | |
play_file(audiofiles[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment