Arduino speaker seems not to be working according to my code. It is not shutting off the sound.
I am trying to run the code below. However, when I press the button all I get is one long, continuous sound. When I change the frequency, the tone also changes, so it appears to be reading the frequency correctly, but it wont change the frequency when I adjust the potentiometer.
I also tried running a smaller piece of code where it should only play a sound for 1 second. When I ran the code, the speaker had the same result: the speaker made one sound and wouldn't stop until I unplugged the Arduino.
Why is this happening and how can I solve it?
board = PyMata3(com_port="com5")
pot = Pot(board, PIN_POT, 10)
spkr = Speaker(board, PIN_SPEAKER)
led = Led(board, PIN_LED0)
button = Button(board, PIN_SW0, activeLevel=0, internalPull=1)
while True:
if button.isPressed():
if pot.fraction() < 0.3:
spkr.play(50)
if 0.3 <= pot.fraction() < 0.65:
spkr.play(100)
if 0.65 <= pot.fraction() <= 1.0:
spkr.play(200)
I'd expect the speaker to change frequency with the adjustment of the potentiometer.
you just called play method. where is the stop / pause ?