Your example worked somewhat. But it wouldnt continiue after pir had seen movement
This is how it looks after ive been tinkering.
The error is here on line 17:
This is how it looks after ive been tinkering.
The error is here on line 17:
end time = time.time + (light_on_delay * 60)And this is the error message:
File "button.py", line 17 end time = time.time + (light_on_delay * 60) ^ SyntaxError: invalid syntax
import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.IN) #Read output from PIR motion sensor GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) light_on_delay = 15 # time in min for light to stay on when button pressed button_pressed = 0 while True: # check for button press input_state = GPIO.input(18) if input_state == False: print('Button Pressed') end time = time.time + (light_on_delay * 60) button_pressed = 1 #exec(open("./LightsOn.py").read(), globals()) print('button push') # check if button has been pressed if it has check to see if time is up if button_pressed == 1: if time.time > end: button_pressed = 0 else: i=GPIO.input(4) if i==0: #When output from motion sensor is LOW print ('No movement detected - Turning lights off') #exec(open("./LightsOn.py").read(), globals()) print ('off') time.sleep(0.1) else: #When output from motion sensor is HIGH print ('Movement detected - Turning lights on') #exec(open("./LightsOff.py").read(), globals()) print ('on') time.sleep(60 * 15) # added delay to prevent program using 100% cpu time. time.sleep(0.5)