11 # GPIO17 YEL_PIN = 12 # GPIO18 GRN_PIN = 13 # GPIO27 GPIO.setup(RED_PIN, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(YEL_PIN, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(GRN_PIN, GPIO.OUT, initial=GPIO.LOW) try: while True: GPIO.output(RED_PIN, GPIO.HIGH) time.sleep(4) GPIO.output(RED_PIN, GPIO.LOW) GPIO.output(YEL_PIN, GPIO.HIGH) time.sleep(2) GPIO.output(YEL_PIN, GPIO.LOW) GPIO.output(GRN_PIN, GPIO.HIGH) time.sleep(4) GPIO.output(GRN_PIN, GPIO.LOW) except KeyboardInterrupt: print "Exception: KeyboardInterrupt" finally: GPIO.cleanup() 完整程式碼 請查看 traffic_light_nonstructure.py 紅綠燈亮燈 這邊一樣要改引腳編號!