SHARE
TWEET

Untitled

a guest Oct 21st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from gpiozero import MotionSensor
  2. import pygame
  3. import time
  4. import random
  5.  
  6. pygame.mixer.init()
  7. #load an array of sound files, they're all in the home directory under halloween
  8. halloween_sounds = [
  9.     pygame.mixer.Sound("/home/pi/Desktop/halloween_sounds/hauntedhouse.wav"),
  10.     pygame.mixer.Sound("/home/pi/Desktop/halloween_sounds/evil_laugh.wav"),
  11.     pygame.mixer.Sound("/home/pi/Desktop/halloween_sounds/ghost.wav"),
  12.     pygame.mixer.Sound("/home/pi/Desktop/halloween_sounds/scream.wav"),
  13.     pygame.mixer.Sound("/home/pi/Desktop/halloween_sounds/witch_laugh.wav")
  14. ]
  15.  
  16. pir = MotionSensor(4)
  17.  
  18. while True:
  19.     pir.wait_for_motion()
  20.     while pygame.mixer.get_busy() != True:
  21.         print("Motion Detected")
  22.         random_sound = random.choice(halloween_sounds);
  23.         random_sound.play()
  24.         time.sleep(15)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top