BOARD -> pin number
BCM -> GPIO number
舉例來說....如果你要用GPIO 2 ....
如果你設的是BCM....就是 2...
BOARD ..就是 3
#!/usr/bin/python
import RPi.GPIO as GPIO
dout1 = 6 # Broadcom pin 3
dout2 = 13 # Broadcom pin 5
dout3 = 19 # Broadcom pin 7
dout4 = 26 # Broadcom pin 11
GPIO.setmode(GPIO.BCM)
GPIO.setup(dout1,GPIO.OUT)
GPIO.setup(dout2,GPIO.OUT)
GPIO.setup(dout3,GPIO.OUT)
GPIO.setup(dout4,GPIO.OUT)
GPIO.output(dout1, GPIO.LOW)
GPIO.output(dout2, GPIO.LOW)
GPIO.output(dout3, GPIO.LOW)
GPIO.output(dout4, GPIO.LOW)
while True:
print "please input key : (a -> left, w -> front, d -> right, x -> back, c -> quit)"
a = raw_input()
print "you input is " + str(a)
if a == 'd': # right
GPIO.output(dout1, GPIO.LOW)
GPIO.output(dout2, GPIO.HIGH)
GPIO.output(dout3, GPIO.HIGH)
GPIO.output(dout4, GPIO.LOW)
elif a == 'a': # left
GPIO.output(dout1, GPIO.HIGH)
GPIO.output(dout2, GPIO.LOW)
GPIO.output(dout3, GPIO.LOW)
GPIO.output(dout4, GPIO.HIFG)
elif a == 'x': # back
GPIO.output(dout1, GPIO.LOW)
GPIO.output(dout2, GPIO.HIGH)
GPIO.output(dout3, GPIO.LOW)
GPIO.output(dout4, GPIO.HIGH)
elif a == 'w': # front
GPIO.output(dout1, GPIO.HIGH)
GPIO.output(dout2, GPIO.LOW)
GPIO.output(dout3, GPIO.HIGH)
GPIO.output(dout4, GPIO.LOW)
elif a == 'c': # quit
break;
GPIO.output(dout1, GPIO.LOW)
GPIO.output(dout2, GPIO.LOW)
GPIO.output(dout3, GPIO.LOW)
GPIO.output(dout4, GPIO.LOW)
GPIO.cleanup()
=============================================================
2/7 update... 加入聲控.....
http://0975128810.blogspot.tw/2016/02/use-raspberry-for-voice-control.html
=============================================================