File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import board
2+ from digitalio import DigitalInOut , Direction , Pull
3+ import audioio
4+ import neopixel
5+ import time
6+
7+ filename = "electrons.wav"
8+
9+ # What pad our button is connected to:
10+ button = DigitalInOut (board .A4 )
11+ button .direction = Direction .INPUT
12+ button .pull = Pull .UP
13+
14+ pixels = neopixel .NeoPixel (board .NEOPIXEL , 10 , brightness = 1 )
15+
16+ # NeoPixel Animation
17+ def simpleCircle (wait ):
18+ PURPLE = (255 , 0 , 255 )
19+ BLACK = (0 , 0 , 0 )
20+ CYAN = (0 , 255 , 255 )
21+ ORANGE = (255 , 255 , 0 )
22+
23+ for i in range (len (pixels )):
24+ pixels [i ] = PURPLE
25+ time .sleep (wait )
26+ for i in range (len (pixels )):
27+ pixels [i ] = CYAN
28+ time .sleep (wait )
29+ for i in range (len (pixels )):
30+ pixels [i ] = ORANGE
31+ time .sleep (wait )
32+ for i in range (len (pixels )):
33+ pixels [i ] = BLACK
34+ time .sleep (wait )
35+
36+ # Audio Stuff
37+ def play_file (filename ):
38+ print ("Playing File" + filename )
39+ wave_file = open (filename , "rb" )
40+ with audioio .WaveFile (wave_file ) as wave :
41+ with audioio .AudioOut (board .A0 ) as audio :
42+ audio .play (wave )
43+ while audio .playing :
44+ pass
45+ simpleCircle (.02 )
46+ print ("finished" )
47+
48+ while True :
49+ if not button .value :
50+ play_file (filename )
You can’t perform that action at this time.
0 commit comments