mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2026-01-12 04:15:47 +00:00
Convert recipe examples to includes
Makes it much easier to test things - no copying'n'pasting just run the examples straight from the dir (after wiring stuff up)
This commit is contained in:
18
docs/examples/music_box.py
Normal file
18
docs/examples/music_box.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from gpiozero import Button
|
||||
import pygame.mixer
|
||||
from pygame.mixer import Sound
|
||||
from signal import pause
|
||||
|
||||
pygame.mixer.init()
|
||||
|
||||
sound_pins = {
|
||||
2: Sound("samples/drum_tom_mid_hard.wav"),
|
||||
3: Sound("samples/drum_cymbal_open.wav"),
|
||||
}
|
||||
|
||||
buttons = [Button(pin) for pin in sound_pins]
|
||||
for button in buttons:
|
||||
sound = sound_pins[button.pin.number]
|
||||
button.when_pressed = sound.play
|
||||
|
||||
pause()
|
||||
Reference in New Issue
Block a user