I'm trying to build a soundboard that plays samples on a button press. I have the sounds playing and stopping on the button press, however, I cant for the life of me figure out how to get the sounds to play on a continuous loop until the button is pressed again.
I've search google and the forums and figure it has something to do with the hold_repeat function on gpiozero but I don't have much coding experience and cant work out where to fit it in the code.
The code I'm using is:
Code: Select all
import pygame.mixer
from pygame.mixer import Sound
from gpiozero import Button
from signal import pause
pygame.mixer.init()
sound_pins = {
2: Sound("samples/sound1.wav"),
3: Sound("samples/sound2.wav"),
}
print "pedal ready"
buttons = [Button(pin) for pin in sound_pins]
for button in buttons:
sound = sound_pins[button.pin.number]
button.when_pressed = sound.play
button.when_released = sound.stop
pause()
Any help would be greatly appreciated.