# Doves Repellent
# by Roni Bandini
# Buenos Aires, Argentina, Oct-2015
# @ronibandini 

import RPi.GPIO as GPIO
import time
import pygame

# init mixer
pygame.mixer.init()


# Connect PIR to pin 7
GPIO.setmode(GPIO.BCM)
PIR_PIN = 7
GPIO.setup(PIR_PIN, GPIO.IN)

# led pin
GPIO.setup(8, GPIO.OUT)
GPIO.output(8, False)



def MOTION(PIR_PIN):
               print "Doves detected"
	       GPIO.output(8, True)	      	
	       pygame.mixer.music.play()
	       time.sleep(3)
	       GPIO.output(8, False)
	       while pygame.mixer.music.get_busy() == True:
    			continue

print "Doves Repellent by Roni Bandini (CTRL+C to exit)"
print "System armed"
# load armed sound
pygame.mixer.music.load("armed.mp3")
pygame.mixer.music.play()
time.sleep(3)

# load predator sounds, using hawk instead of owl, you can replace the mp3
pygame.mixer.music.load("hawk.mp3")

try:
               GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)
               while 1:
                              time.sleep(10)
except KeyboardInterrupt:
               print "Exit"
               GPIO.cleanup()
