Skip to content

Commit

Permalink
Added comments, frequency variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kattni committed Jul 10, 2018
1 parent 7123fb9 commit b8ef37f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CircuitPython_Essentials/CircuitPython_Audio_Out_Tone.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
button.switch_to_input(pull=digitalio.Pull.UP)

tone_volume = 0.1 # Increase this to increase the volume of the tone.
length = 8000 // 440
frequency = 440 # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
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))
Expand Down
3 changes: 3 additions & 0 deletions CircuitPython_Essentials/CircuitPython_Audio_Out_Wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

while True:
audio.play(wave)

# This allows you to do other things while the audio plays!
t = time.monotonic()
while time.monotonic() - t < 6:
pass

audio.pause()
print("Waiting for button press to continue!")
while button.value:
Expand Down

0 comments on commit b8ef37f

Please sign in to comment.