Skip to content

Update CircuitPython_I2S_Tone.py #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Adafruit_MAX98357/CircuitPython_I2S_Tone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import board
import audiobusio

tone_volume = 0.1 # Increase this to increase the volume of the tone.
sample_rate = 8000
tone_volume = .1 # Increase or decrease this to adjust the volume of the tone.
frequency = 440 # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
length = sample_rate // frequency # One freqency period
sine_wave = array.array("H", [0] * length)
for i in range(length):
sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / 18)) * tone_volume * (2 ** 15))
sine_wave[i] = int((math.sin(math.pi * 2 * frequency * i / sample_rate) *
tone_volume + 1) * (2 ** 15 - 1))

# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
audio = audiobusio.I2SOut(board.D1, board.D0, board.D9)
# For Feather M4 Express
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
# For Metro M4 Express
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
sine_wave_sample = audioio.RawSample(sine_wave)
sine_wave_sample = audioio.RawSample(sine_wave, sample_rate=sample_rate)

while True:
audio.play(sine_wave_sample, loop=True)
Expand Down