import RPi.GPIO as GPIO
import time
import subprocess
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_PIR = 7
print "PIR Module Test (CTRL-C to exit)"
# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN) # Echo
Current_State = 0
Previous_State = 0
try:
print "Waiting for PIR to settle ..."
# Loop until PIR output is 0
while GPIO.input(GPIO_PIR)==1:
Current_State = 0
print " Ready"
# Loop until users quits with CTRL-C
while True :
# Read PIR state
Current_State = GPIO.input(GPIO_PIR)
if Current_State==1 and Previous_State==0:
# PIR is triggered
print " Motion detected!"
#subprocess.call("sudo python /home/pi/Desktop/smspyserial.py", shell=True)
#subprocess.call("mpg123 /home/pi/Minion-Banana.mp3", shell=True)
# Record previous state
Previous_State=1
elif Current_State==0 and Previous_State==1:
# PIR has returned to ready state
print " Ready"
subprocess.call("sudo python /home/pi/Desktop/smspyserial.py", shell=True)
subprocess.call("sudo python /home/pi/Desktop/smspyserial2.py", shell=True)
Previous_State=0
# Wait for 10 milliseconds
time.sleep(0.01)
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
#yang dipakai untuk PIR = PIN 2 warna merah,PIN 6 warna hitam,PIN 26 warna Kuning..
#yang dipakai untuk LED = PIN 12 sama PIN 16,terus PIN 25 buat GROUND
Tidak ada komentar:
Posting Komentar