Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame.mixer
- import RPi.GPIO as GPIO
- from sys import exit
- import random
- import time
- import glob
- import pygame.event
- attack = glob.glob("attack/*.wav") #folder with attack quotes
- move = glob.glob("movement/*.wav") #folder with move/idle quotes
- taunt = glob.glob("taunt/*.wav") #folder with taunt quotes
- joke = glob.glob("joke/*.wav") #folder with the jokes
- laugh = glob.glob("laugh/*.wav") #folder with the laughing tracks
- pick = glob.glob("pick/*.wav") #folder with pick/ban quotes
- misc = glob.glob("misc/*.wav")
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(17, GPIO.IN)
- GPIO.setup(18, GPIO.IN)
- GPIO.setup(27, GPIO.IN)
- GPIO.setup(22, GPIO.IN)
- GPIO.setup(23, GPIO.IN)
- GPIO.setup(24, GPIO.IN)
- GPIO.setup(25, GPIO.IN)
- pygame.mixer.init(48000, -16, 1, 1024)
- SoundA = pygame.mixer.Channel(1)
- SoundB = pygame.mixer.Channel(2)
- SoundC = pygame.mixer.Channel(3)
- SoundD = pygame.mixer.Channel(4)
- SoundE = pygame.mixer.Channel(5)
- SoundF = pygame.mixer.Channel(6)
- SoundG = pygame.mixer.Channel(7)
- attack_sounds = []
- for sound_file in glob.glob("attack/*.wav"):
- attack_sounds.append(pygame.mixer.Sound(sound_file))
- move_sounds = []
- for sound_file in glob.glob("movement/*.wav"):
- move_sounds.append(pygame.mixer.Sound(sound_file))
- taunt_sounds = []
- for sound_file in glob.glob("taunt/*.wav"):
- taunt_sounds.append(pygame.mixer.Sound(sound_file))
- joke_sounds = []
- for sound_file in glob.glob("joke/*.wav"):
- attack_sounds.append(pygame.mixer.Sound(sound_file))
- laugh_sounds = []
- for sound_file in glob.glob("laugh/*.wav"):
- laugh_sounds.append(pygame.mixer.Sound(sound_file))
- pick_sounds = []
- for sound_file in glob.glob("pick/*.wav"):
- pick_sounds.append(pygame.mixer.Sound(sound_file))
- misc_sounds = []
- for sound_file in glob.glob("misc/*.wav"):
- misc_sounds.append(pygame.mixer.Sound(sound_file))
- print ("Soundboard aktiv.");
- while True:
- try:
- if (GPIO.input(17) == True):
- random_sound = random.choice(attack_sounds)
- random_sound.play()
- if (GPIO.input(18) == True):
- random_sound = random.choice(move_sounds)
- random_sound.play()
- if (GPIO.input(27) == True):
- random_sound = random.choice(taunt_sounds)
- random_sound.play()
- if (GPIO.input(22) == True):
- random_sound = random.choice(joke_sounds)
- random_sound.play()
- if (GPIO.input(23) == True):
- random_sound = random.choice(laugh_sounds)
- random_sound.play()
- if (GPIO.input(24) == True):
- random_sound = random.choice(pick_sounds)
- random_sound.play()
- if (GPIO.input(25) == True):
- random_sound = random.choice(misc_sounds)
- random_sound.play()
- except KeyboardInterrupt:
- exit()
- time.sleep(2)
Add Comment
Please, Sign In to add comment