|   
		
 テストに使用するプログラム
 ── tilt を検知したら LED が点灯 (衝撃に対しても点灯)
 | #!/usr/bin/python
import RPi.GPIO as GPIO
TiltPin = 18
LedPin = 16
def setup():
	# Set the GPIO pins as numbering
	GPIO.setmode(GPIO.BOARD)
	# Set the TiltPin's mode is input, and (Not detected→) ON→ LOW
	GPIO.setup(TiltPin, 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(TiltPin) == 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 sw_520d.py
 
 $ chmod +x sw_520d.py
 
 $ ./sw_520d.py
 
 
 
 |