我是Python命令的新手。在我的程序命令中,当磁门传感器打开时,我需要程序返回主程序。这意味着当门传感器打开时,程序将循环到第一个命令行。有人能帮我吗?下面是我的程序的命令行。在
#function for door closing
def door_open():
print("Door Open")
# function for the door closing
def door_close():
print("Door Close")
def main():
while True:
if GPIO.input(door_sensor): # if door is opened
if (sensorTrigger):
door_open() # fire GA code
sensorTrigger = False # make sure it doesn't fire again
if not io.input(door_sensor): # if door is closed
if not (sensorTrigger):
door_close() # fire GA code
sensorTrigger = True # make sure it doesn't fire again
door_close_thread = threading.Thread(target=door_close)
door_close_thread.daemon = True
door_close_thread.start()
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"
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!"
# Record previous state
Previous_State=1
if not Current_State==0 and Previous_State==1:
# PIR has returned to ready state
print " Ready"
Previous_State=0
# Wait for 10 milliseconds
time.sleep(0.01)
except keyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
尝试递归调用主函数。在
相关问题 更多 >
编程相关推荐