本帖最后由 lingku 于 2013-3-11 13:12 编辑
入手Raspberry pi有段时间了,一直用作xbmc来用。
今天查了下python rpi.gpio库,发现操作还是很方便的,手头也正好有个很早之前焊接的8led灯的小板,于是就写了个简单的跑马灯:
注:代码中的led_port_list管脚是BCM上的管脚,具体可参考下图:
硬件参考wiki:http://www.elinux.org/Rpi_Low-level_peripherals- #!/usr/bin/env python
- # coding: utf-8
- #Note:
- # para 'initial' may not work in lower version
- # You can use following cmd to upgrade PRi.GPIO to the latest version:
- # sudo apt-get install python-rpi.gpio
- import RPi.GPIO as GPIO
- import time
- led_port_list = [14, 15, 18, 23, 24, 25, 8, 7]
- def led_init():
- GPIO.setmode(GPIO.BCM)
- for port in led_port_list:
- GPIO.setup(port, GPIO.OUT, initial=GPIO.LOW)
- def led_start():
- while True:
- for port in led_port_list:
- GPIO.output(port, True)
- time.sleep(0.1) #sleep
- GPIO.output(port, False)
- if __name__ == '__main__':
- led_init()
- led_start()
复制代码 |