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