刚拿到一块HLK-LD020,我把VCC接到树莓派4B的5V上,GND接到树莓派4B的GND上,OUT接到树莓派4B的GPIO17。用下面的代码,一直输出LOW。请问一下这么用哪里不对,应该怎么改?
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
PIN = 17
GPIO.setup(PIN, GPIO.IN)
try:
while True:
level = GPIO.input(PIN)
if level == GPIO.HIGH:
print("High")
else:
print("Low")
time.sleep(0.1)
except KeyboardInterrupt:
print("退出")
finally:
GPIO.cleanup()