【问题标题】:Arduino Speaker making long continuous noiseArduino 扬声器发出长时间连续的噪音
【发布时间】:2019-03-31 00:55:51
【问题描述】:

Arduino 扬声器似乎没有按照我的代码工作。它没有关闭声音。

我正在尝试运行下面的代码。然而,当我按下按钮时,我得到的只是一种长而连续的声音。当我改变频率时,音调也会改变,所以它似乎正在正确读取频率,但是当我调整电位器时它不会改变频率。

我还尝试运行一小段代码,它应该只播放 1 秒钟的声音。当我运行代码时,扬声器有相同的结果:扬声器发出一个声音,直到我拔掉 Arduino 才停止。

为什么会发生这种情况,我该如何解决?

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)

我希望扬声器可以通过调节电位器来改变频率。

【问题讨论】:

    标签: python arduino arduino-uno speaker


    【解决方案1】:

    你刚刚调用了 play 方法。停止/暂停在哪里?

    【讨论】:

    • 是的。就是这样。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    相关资源
    最近更新 更多