水位指示器 - Raspberry Pi
Water Level Indicator - Rasp Pi
我正在创建一个项目,它是带有 raspberry pi 的水位指示器。所以当我把电线放入水中时,led会自动亮起。
我的问题是我想在第二根电线接触到水时关闭第一个 LED。
这是示例图片:
Click here for the image
这是我的示例代码
while True:
GPIO.output(led8output, 0)
GPIO.output(led10output, 0)
if GPIO.input(led8input) == 1:
GPIO.output(led8output, 1)
if GPIO.input(led10input) == 1:
GPIO.output(led10output, 1)
GPIO.output(led8output, 0) #this code wont make the first led turn off.
我什至试过 elif 和 if(GPIO.input(led10input) == 1 和 GPIO.input(led8input) ==1) 都不起作用。请帮忙。谢谢
试试这个:
GPIO.output(led8output, 0)
GPIO.output(led10output, 0)
while True:
if GPIO.input(led8input) == 1 and GPIO.input(led10input) == 0:
print "1st led has been turned on"
GPIO.output(led8output, 1)
if GPIO.input(led10input) == 1 and GPIO.input(led8input) == 1:
print "Both leds have been turned on therefore turning 1st led off"
GPIO.output(led10output, 1)
GPIO.output(led8output, 0)
我正在创建一个项目,它是带有 raspberry pi 的水位指示器。所以当我把电线放入水中时,led会自动亮起。
我的问题是我想在第二根电线接触到水时关闭第一个 LED。
这是示例图片:
Click here for the image
这是我的示例代码
while True:
GPIO.output(led8output, 0)
GPIO.output(led10output, 0)
if GPIO.input(led8input) == 1:
GPIO.output(led8output, 1)
if GPIO.input(led10input) == 1:
GPIO.output(led10output, 1)
GPIO.output(led8output, 0) #this code wont make the first led turn off.
我什至试过 elif 和 if(GPIO.input(led10input) == 1 和 GPIO.input(led8input) ==1) 都不起作用。请帮忙。谢谢
试试这个:
GPIO.output(led8output, 0)
GPIO.output(led10output, 0)
while True:
if GPIO.input(led8input) == 1 and GPIO.input(led10input) == 0:
print "1st led has been turned on"
GPIO.output(led8output, 1)
if GPIO.input(led10input) == 1 and GPIO.input(led8input) == 1:
print "Both leds have been turned on therefore turning 1st led off"
GPIO.output(led10output, 1)
GPIO.output(led8output, 0)