File tree Expand file tree Collapse file tree
Introducing_CircuitPlaygroundExpress Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import audioio
21import board
32import digitalio
43
5- # enable the speaker
4+ try :
5+ from audiocore import WaveFile
6+ except ImportError :
7+ from audioio import WaveFile
8+
9+ try :
10+ from audioio import AudioOut
11+ except ImportError :
12+ try :
13+ from audiopwmio import PWMAudioOut as AudioOut
14+ except ImportError :
15+ pass # not always supported by every board!
16+
17+ # Enable the speaker
618spkrenable = digitalio .DigitalInOut (board .SPEAKER_ENABLE )
719spkrenable .direction = digitalio .Direction .OUTPUT
820spkrenable .value = True
921
10- # make the 2 input buttons
22+ # Make the 2 input buttons
1123buttonA = digitalio .DigitalInOut (board .BUTTON_A )
1224buttonA .direction = digitalio .Direction .INPUT
1325buttonA .pull = digitalio .Pull .DOWN
2335def play_file (filename ):
2436 print ("Playing file: " + filename )
2537 wave_file = open (filename , "rb" )
26- with audioio . WaveFile (wave_file ) as wave :
27- with audioio . AudioOut (board .A0 ) as audio :
38+ with WaveFile (wave_file ) as wave :
39+ with AudioOut (board .SPEAKER ) as audio :
2840 audio .play (wave )
2941 while audio .playing :
3042 pass
Original file line number Diff line number Diff line change 11import time
22import array
33import math
4- import audioio
54import board
65import digitalio
76
7+ try :
8+ from audiocore import RawSample
9+ except ImportError :
10+ from audioio import RawSample
11+
12+ try :
13+ from audioio import AudioOut
14+ except ImportError :
15+ try :
16+ from audiopwmio import PWMAudioOut as AudioOut
17+ except ImportError :
18+ pass # not always supported by every board!
19+
820FREQUENCY = 440 # 440 Hz middle 'A'
921SAMPLERATE = 8000 # 8000 samples/second, recommended!
1022
1426for i in range (length ):
1527 sine_wave [i ] = int (math .sin (math .pi * 2 * i / 18 ) * (2 ** 15 ) + 2 ** 15 )
1628
17- # enable the speaker
29+ # Enable the speaker
1830speaker_enable = digitalio .DigitalInOut (board .SPEAKER_ENABLE )
1931speaker_enable .direction = digitalio .Direction .OUTPUT
2032speaker_enable .value = True
2133
22- audio = audioio . AudioOut (board .A0 )
23- sine_wave_sample = audioio . RawSample (sine_wave )
34+ audio = AudioOut (board .SPEAKER )
35+ sine_wave_sample = RawSample (sine_wave )
2436
25- audio .play (sine_wave_sample , loop = True ) # keep playing the sample over and over
37+ audio .play (sine_wave_sample , loop = True ) # Keep playing the sample over and over
2638time .sleep (1 ) # until...
27- audio .stop () # we tell the board to stop
39+ audio .stop () # We tell the board to stop
You can’t perform that action at this time.
0 commit comments