共享个跑马灯代码:- #!/usr/bin/env python
- # coding: utf-8
- 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.HIGH)
- #GPIO.output(port, False)
- time.sleep(1)
- for port in led_port_list:
- GPIO.output(port, False)
- 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()
复制代码 |