Of course, not able to test, but something like this
Didn't change the rest of the code, but probably it could be written better. At least, based on https://sourceforge.net/p/raspberry-gpio...ki/Inputs/ it's better to use edge detection than pooling
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) #Top Switch #GPIO.setup(12,GPIO.IN) # Bottom Switch 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 delay1 = 1 # time between checks when door moving for switch operation may need to be shorter delay2 = 5 # time between checks of LDR while True: while GPIO.input(7) == False: if GPIO.input(11) == False: print ("Day") print ("Open door") GPIO.output(15,True) print ("drive motor") print ("Current time %s" % now ) elif GPIO.input(11) == True: GPIO.output(15,False) print ("STOP door open") send_sms(client=twilio_client, sms_text='Door open') time.sleep(delay1) time.sleep(delay2) while GPIO.input(7) == True: if GPIO.input(12) == False: print ("Night") print ("Close door") GPIO.output(13,True) print ("drive motor") elif GPIO.input(12) == True: GPIO.output(13,False) print ("STOP door closed") send_sms(client=twilio_client, sms_text='Door closed') time.sleep(delay1) time.sleep(delay2)I changed the indentation to 4 spaces, as per PEP8. 8 spaces per level is way too much.
Didn't change the rest of the code, but probably it could be written better. At least, based on https://sourceforge.net/p/raspberry-gpio...ki/Inputs/ it's better to use edge detection than pooling
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs