Skip to content

Instantly share code, notes, and snippets.

@westy48
Created December 5, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westy48/3fb911f2239337fd6d02ac877f9b530c to your computer and use it in GitHub Desktop.
Save westy48/3fb911f2239337fd6d02ac877f9b530c to your computer and use it in GitHub Desktop.
Updated version of code for Christmas LEDs and sounds
# 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