Last active
September 6, 2020 00:45
-
-
Save rowena-s/6cbf910f21af6884edac18e0f6c891cd to your computer and use it in GitHub Desktop.
Code for Wearing Your Python and Making It Sing Too! 2020 #pyconlineau talk
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
#instrument samples can be obtained from https://philharmonia.co.uk/resources/sound-samples/ | |
#file conversion instructions: https://learn.adafruit.com/microcontroller-compatible-audio-file-conversion | |
from adafruit_circuitplayground.express import cpx | |
from time import sleep | |
cpx.pixels.brightness = 0.1 | |
ctr = 0 | |
while True: | |
if cpx.touch_A1: | |
ctr = 0 | |
cpx.pixels.fill((0,100,0)) | |
if cpx.button_a: | |
cpx.play_file("flute_C5.wav") | |
else: | |
cpx.play_file("flute_C4.wav") | |
elif cpx.touch_A2: | |
ctr = 0 | |
cpx.pixels.fill((255,100,0)) | |
cpx.play_file("flute_D4.wav") | |
elif cpx.touch_A3: | |
ctr = 0 | |
cpx.pixels.fill((255,215,0)) | |
cpx.play_file("flute_E4.wav") | |
elif cpx.touch_A4: | |
ctr = 0 | |
cpx.pixels.fill((255, 0, 0)) | |
if cpx.button_a: | |
cpx.play_file("sax_G3.wav") | |
else: | |
cpx.play_file("flute_G4.wav") | |
elif cpx.touch_A5: | |
ctr = 0 | |
cpx.pixels.fill((75,0,130)) | |
if cpx.button_a: | |
cpx.play_file("sax_A3.wav") | |
else: | |
cpx.play_file("flute_A4.wav") | |
#make a delay for the lights to turn off instead of after every loop | |
if ctr == 4: | |
cpx.pixels.fill((0,0,0)) | |
ctr += 1 | |
sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment