我正在尝试创建一个脚本来运行一个门来打开和关闭它,当它碰到限位开关时,它将停止。车门由光传感器启动。在
到目前为止,我的光传感器和电机的代码工作良好,但我不确定最好的地方是把“当开关顶部==true”停止电机。在
有谁能建议最好的陈述地点吗?或者有没有我应该使用的函数?在
while True:
def relay( state ):
if (state == 'Open'):
GPIO.output(3,False)
else:
GPIO.output(3,True)
return
humidity, temperature = Adafruit_DHT.read_retry(11, 17)
lcd.clear()
lcd.cursor_pos = (1, 0)
lcd.write_string("Temp:%dC"% temperature)
if (GPIO.input(INPUT_PIN) == False):
relay('Open')
print('Open')
lcd.cursor_pos = (0, 0)
lcd.write_string("Door open")
else:
relay('Close')
print('Close')
lcd.cursor_pos = (0, 0)
lcd.write_string("Door close")
time.sleep(1)
GPIO.cleanup()
目前没有回答
相关问题 更多 >
编程相关推荐