Mar-31-2018, 10:28 AM
(Mar-31-2018, 10:00 AM)buran Wrote: Again, not able to test, but I think this should worknot sure still looking at it but won't run getting invalid syntax looks like line 30
import RPi.GPIO as GPIO import time from twilio.rest import Client def send_sms(client, sms_text="Hello from Python!"): client.messages.create(to="+19732644152", from_="+12023351278", body=sms_text) twilio_client = Client("ACxxxxxxxxxxxxxx", "zzzzzzzzzzzzz") GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(7,GPIO.IN) #LDR (Light Dependent Resistor) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #top switch GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # bottom switch GPIO.setup(15,GPIO.OUT) # Door Open GPIO.setup(13,GPIO.OUT) # Door Close # add events detection GPIO.add_event_detect(7, GPIO.BOTH) GPIO.add_event_detect(11, GPIO.RISING) GPIO.add_event_detect(12, GPIO.RISING) while True: if GPIO.event_detected(7) # change in light sensor if GPIO.input(7) == False and GPIO.input(11) == False: # it's day and door is not open print ("Day") print ("Open door") GPIO.output(15,True) print ("Start motor") print ("Current time %s" % now ) elif GPIO.input(7) == True and GPIO.input(12) == False: # it's night and door is not closed print ("Night") print ("Close door") GPIO.output(13,True) print ("Drive motor") if GPIO.event_detected(11): # top switch change to HIGH GPIO.output(15,False) print ("STOP door open") send_sms(client=twilio_client, sms_text='Door open') if GPIO.event_detected(12): # bottom switch change to HIGH GPIO.output(13,False) print ("STOP door closed") send_sms(client=twilio_client, sms_text='Door closed')Maybe it can be written better, but let's make it work as expected
if GPIO.event_detected(7) # change in light sensor