テストに使用するプログラム
──タッチを検知したら,LED が点灯
#!/usr/bin/python
import RPi.GPIO as GPIO
SignalPin = 18
LedPin = 16
def setup():
# Set the GPIO pins as numbering
GPIO.setmode(GPIO.BOARD)
# Set the SignalPin's mode is input, and (Not detected→) ON→ LOW
GPIO.setup(SignalPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Set the LedPin's mode is output
GPIO.setup(LedPin,GPIO.OUT)
# Set the LedPin low
GPIO.output(LedPin, GPIO.LOW)
def destroy():
# Release resource
GPIO.cleanup()
def loop():
while True:
if GPIO.input(SignalPin) == GPIO.HIGH:
GPIO.output(LedPin,GPIO.HIGH)
else:
GPIO.output(LedPin,GPIO.LOW)
# 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 ky_036.py
$ chmod +x ky_036.py
$ ./ky_036.py
|