import RPi.GPIO as GPIO
import time
import datetime
import os
GPIO.setmode(GPIO.BCM)
pir_pin = 23
GPIO.setup(pir_pin, GPIO.IN)
start = datetime.time(23, 30,0)
end = datetime.time(23, 59, 59)
start1 = datetime.time(0, 0, 1)
end1 = datetime.time(5, 0, 0)
pin= 4
def RCtime(pin):
reading = 0
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(pin, GPIO.IN)
while(GPIO.input(pin) == GPIO.LOW):
reading += 1
return reading
counter=0
cmd = "aplay /home/pi/Documents/lightsON.wav"
RCtime(pin)
start_pir = 0
time.sleep(2)
while True:
if GPIO.input(pir_pin):
counter = 0
for i in range(1200):
start_pir += 1
time.sleep(1)
start_pir = 0
x = datetime.datetime.now().time()
if RCtime(pin) < 10000 and counter < 360 and (start<x<end or start1<x<end1):
counter += 1
elif RCtime(pin) < 10000 and counter == 360 and (start<x<end or start1<x<end1) and start_pir==0:
os.system(cmd)
time.sleep(10)
os.system(cmd)
counter=0
elif RCtime(pin) > 10000:
counter=0
time.sleep(1)
GPIO.cleanup()
sys.exit()