Created
December 5, 2016 22:16
-
-
Save westy48/3fb911f2239337fd6d02ac877f9b530c to your computer and use it in GitHub Desktop.
Updated version of code for Christmas LEDs and sounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import Python libraries | |
from gpiozero import LED, PWMLED, Button | |
import pygame.mixer | |
from pygame.mixer import Sound | |
import time | |
from signal import pause | |
import random | |
import os | |
pygame.mixer.init() | |
randomfile = "" | |
file = "" | |
# Set the GPIO pins | |
led = PWMLED(24) | |
button = Button(3) | |
while True: | |
button.wait_for_press() | |
time.sleep(0.25) | |
led.pulse(n=10) | |
randomfile = random.sample(os.listdir("/home/pi/fright/music/"), 1)[0] | |
print randomfile | |
file = '/home/pi/fright/music/'+ randomfile | |
santa = Sound(file) | |
print file | |
pygame.mixer.music.set_volume(0.5) | |
santa.play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment