当我运行下面的脚本打开灯(状态=打开),然后重新启动覆盆子pi后再次运行脚本它告诉我状态=打开,何时应该关闭。为什么会这样?有什么方法可以解决这个问题吗?
#!/usr/bin/python
import RPi.GPIO as GPIO
#setup GPIO using Board numbering. pin physical number corresponds to gpio call
GPIO.setmode(GPIO.BOARD)
pin=8
GPIO.setup(pin, GPIO.OUT)
state = GPIO.input(pin)
#print 'START: state is: ',state
if state==1:
GPIO.output(pin, False) #lov current turns relay on which breaks circuit on NC and changes state to off
status="off"
else:
GPIO.output(pin, True)
status="on"
print 'light is now: ',status
答案 0 :(得分:0)
您需要调用GPIO.cleanUp();
这是一篇很好的文章,解释何时/为什么/在哪里:RPi.GPIO basics 3 – How to Exit GPIO programs cleanly, avoid warnings and protect your Pi.