GPIO音乐盒Raspberry Pi按钮按下延迟

时间:2018-10-20 13:25:46

标签: python raspberry-pi pygame gpio

我从Raspberry Pi tutorial在线创建了一个GPIO音乐盒。一切似乎都正常,但是button.when_pressed函数有明显的延迟。我有五个按钮,每个按钮都分配给一个小的.wav文件。我在线检查了很多资源,但无法弄清楚。我仍然是Python的新手。最终,我希望能够无延迟地按下每个按钮。任何帮助将非常感激。非常感谢你!

mport pygame
from gpiozero import Button
pygame.init()


button_soundz = {
    Button(27):pygame.mixer.Sound("/home/pi/gpio-music-box/samples/coin.wav"),
    Button(19):pygame.mixer.Sound("/home/pi/gpio-music-box/samples/jump.wav"),
    Button(5):pygame.mixer.Sound("/home/pi/gpio-music-box/samples/zap.wav"),
    Button(10):pygame.mixer.Sound("/home/pi/gpio-music-box/samples/hit_55.wav"),
    Button(20):pygame.mixer.Sound("/home/pi/gpio-music-box/samples/over.wav"),
}

for button, sound in button_soundz.items():
    button.when_pressed = sound.play

0 个答案:

没有答案