Ressources

Catégorie scripts.

Le panda anti Adblock

ch4listing3.py

Script optimisé pour l'ajout / la suppression facile de boutons.
Copier
								
									
from gpiozero import Button
import pygame.mixer
from pygame.mixer import Sound
from signal import pause

pygame.mixer.init()

sound_pins = {
    21: Sound("DrumBuzz.wav"),
    20: Sound("CymbalCrash.wav"),
    16: Sound("Gong.wav"),
    12: Sound("HandClap.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()