树莓派/香蕉派 pro 跑马灯

拿到香蕉派pro,为了熟悉树莓派的系统和python控制GPIO,写个跑马灯玩玩。

 

1、sudo apt-get update

2、sudo apt-get install python-dev

3、按github安装香蕉派pro的rpi.gpio

4、香蕉派pro代码,6个二极管闪烁三次后,开始跑马灯,执行两次后,再次闪烁三次。

import RPi.GPIO as GPIO
import time

# 声明针脚
PIN_8 = 8
PIN_10 = 10
PIN_11 = 11
PIN_13 = 13
PIN_15 = 15
PIN_31 = 31

# 电源长接,所以针脚低电平,灯点亮
myFlag = 0
myTime = 1

GPIO.setmode(GPIO.BOARD)

arr = (PIN_11, PIN_13, PIN_15, PIN_31, PIN_8, PIN_10);

for pin in arr:
    GPIO.setup(pin, GPIO.OUT)

# 所有灯灭
for pin in arr:
    GPIO.output(pin, 1)

i = 0;

while True:

    if i % 2 == 0:
        for num in range(0, 3):
            for pin in arr:
                GPIO.output(pin, 0)
            time.sleep(0.4);
            
            for pin in arr:
                GPIO.output(pin, 1)
            time.sleep(0.4);
        time.sleep(1);
    
    for pin in arr:
        GPIO.output(pin, myFlag)

        for otherPin in arr:
            if pin != otherPin:
                GPIO.output(otherPin, not myFlag)
        
        time.sleep(myTime)

    i = i+1

 

 

 

你可能感兴趣的:(跑马灯)