Added comments, frequency variable
This commit is contained in:
parent
7123fb9da4
commit
b8ef37f0ad
2 changed files with 5 additions and 1 deletions
|
|
@ -9,7 +9,8 @@ button = digitalio.DigitalInOut(board.A1)
|
||||||
button.switch_to_input(pull=digitalio.Pull.UP)
|
button.switch_to_input(pull=digitalio.Pull.UP)
|
||||||
|
|
||||||
tone_volume = 0.1 # Increase this to increase the volume of the tone.
|
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)
|
sine_wave = array.array("H", [0] * length)
|
||||||
for i in range(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((1 + math.sin(math.pi * 2 * i / 18)) * tone_volume * (2 ** 15))
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,12 @@ audio = audioio.AudioOut(board.A0)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
audio.play(wave)
|
audio.play(wave)
|
||||||
|
|
||||||
|
# This allows you to do other things while the audio plays!
|
||||||
t = time.monotonic()
|
t = time.monotonic()
|
||||||
while time.monotonic() - t < 6:
|
while time.monotonic() - t < 6:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
audio.pause()
|
audio.pause()
|
||||||
print("Waiting for button press to continue!")
|
print("Waiting for button press to continue!")
|
||||||
while button.value:
|
while button.value:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue