- 感度調節ネジを回して,感度を調整する。
感度調整のためのプログラムを,以下に示す。
プログラムを走らせ,ネジを回して "Detecting" が適切に表示されるようにする。
#!/usr/bin/python
import RPi.GPIO as GPIO
SignalPin = 18
def setup():
# Set the GPIO pins as numbering
GPIO.setmode(GPIO.BOARD)
# Set the SignalPin's mode as input, and (Not detected→) ON→ LOW
GPIO.setup(SignalPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def destroy():
# Release resource
GPIO.cleanup()
def loop():
while True:
while GPIO.input(SignalPin) == GPIO.LOW:
if GPIO.input(SignalPin) == GPIO.HIGH:
print "Detecting"
break
while GPIO.input(SignalPin) == GPIO.HIGH:
if GPIO.input(SignalPin) == GPIO.LOW:
print "lost"
break
# The Program will start from here
if __name__ == '__main__':
setup()
try:
loop()
# When control c is pressed child program destroy() will be executed.
except KeyboardInterrupt:
destroy()
|
$ vi tcrt5000_setup.py
$ chmod +x tcrt5000_setup.py
$ ./tcrt5000_setup.py
- IR検知のテスト
つぎのプログラムを走らせ,IR検知に対しプログラムが "IR Detected!" を知らせて終了することを確認:
#!/usr/bin/python
import RPi.GPIO as GPIO
SignalPin = 18
def setup():
# Set the GPIO pins as numbering
GPIO.setmode(GPIO.BOARD)
# Set the SignalPin's mode as input, and (Not detected→) ON→ LOW
GPIO.setup(SignalPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def destroy():
# Release resource
GPIO.cleanup()
def loop():
while True:
if GPIO.input(SignalPin) == GPIO.HIGH:
destroy()
print "IR Detected!"
braak
# The Program will start from here
if __name__ == '__main__':
setup()
try:
loop()
# When control c is pressed child program destroy() will be executed.
except KeyboardInterrupt:
destroy()
|
$ vi tcrt5000_test.py
$ chmod +x tcrt5000_test.py
$ ./tcrt5000_test.py
|