File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ CircuitPython PWM Audio Out tone example
7
+ Plays a tone for one second on, one
8
+ second off, in a loop.
9
+ """
10
+ import time
11
+ import array
12
+ import math
13
+ import board
14
+ from audiocore import RawSample
15
+ from audiopwmio import PWMAudioOut as AudioOut
16
+
17
+ audio = AudioOut (board .A1 )
18
+
19
+ tone_volume = 0.1 # Increase this to increase the volume of the tone.
20
+ frequency = 440 # Set this to the Hz of the tone you want to generate.
21
+ length = 8000 // frequency
22
+ sine_wave = array .array ("H" , [0 ] * length )
23
+ for i in range (length ):
24
+ sine_wave [i ] = int ((1 + math .sin (math .pi * 2 * i / length )) * tone_volume * (2 ** 15 - 1 ))
25
+
26
+ sine_wave_sample = RawSample (sine_wave )
27
+
28
+ while True :
29
+ audio .play (sine_wave_sample , loop = True )
30
+ time .sleep (1 )
31
+ audio .stop ()
32
+ time .sleep (1 )
Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ CircuitPython PWM Audio Out WAV example
7
+ Play a WAV file once.
8
+ """
9
+ import board
10
+ from audiocore import WaveFile
11
+ from audiopwmio import PWMAudioOut as AudioOut
12
+
13
+ audio = AudioOut (board .A1 )
14
+
15
+ with open ("StreetChicken.wav" , "rb" ) as wave_file :
16
+ wave = WaveFile (wave_file )
17
+ print ("Playing wav file!" )
18
+ audio .play (wave )
19
+ while audio .playing :
20
+ pass
21
+
22
+ print ("Done!" )
You can’t perform that action at this time.
0 commit comments