You’ll need these audio files too!

import os
from gpiozero import Button, LED
from random import choice
from time import sleep

button = Button(17)
gryffindor = LED(27)
slytherin = LED(6)
hufflepuff = LED(4)
ravenclaw = LED(19)

message = ['Difficult, you are very difficult to sort: ',
         'You are a hero, I know which house you belong to: ',
         'I sense a darkness in your magic: ',
         'When duty calls, you will do your bit for the school: ']
houses = ['Gryffindor','Slytherin','Hufflepuff','Ravenclaw']
music = ['applause.wav', 'WilhelmScream.wav', 'buzzer.wav', 'Scream.wav']
print('Press the button to learn which house you will be joining.')

while True:
	button.wait_for_press()
	house = choice(houses)
	print('Hmmm....let me see.....')
        sleep(2)

if house == 'Gryffindor':
	gryffindor.blink(0.2,0.2)
	print(message[0], house)
	play = (music[0])
	os.system("aplay {0}".format(play))
	sleep(1)
	gryffindor.off()

elif house == 'Slytherin':
	slytherin.blink(0.2,0.2)
	print(message[2], house)
	play = (music[1])
	os.system("aplay {0}".format(play))
	sleep(3)
	slytherin.off()

elif house == 'Hufflepuff':
	hufflepuff.blink(0.2,0.2)
	print(message[3], house)
	play = (music[2])
	os.system("aplay {0}".format(play))
	sleep(3)
	hufflepuff.off()

elif house == 'Ravenclaw':
	ravenclaw.blink(0.2,0.2)
	print(message[1], house)
	play = (music[3])
	os.system("aplay {0}".format(play))
	sleep(3)
	ravenclaw.off()

print('\n')
print('Who\'s next? Press the button to learn which house you will be joining.')
sleep(0.2)

Leave a Reply

Your email address will not be published. Required fields are marked *