码迷,mamicode.com
首页 > 其他好文 > 详细

用树莓派控制8*8led矩阵显示红心

时间:2016-10-08 03:03:09      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:8*8led

话不多说,直接列代码,采用每行扫描显示的方式,led矩阵接口可查参考资料,对应连接相应的树莓派GPIO口。

import RPi.GPIO as GPIO
import time


PIN_A=11
PIN_B=12
PIN_C=13
PIN_D=15
PIN_E=16
PIN_F=18
PIN_G=22
PIN_H=24


PIN_a=29
PIN_b=31
PIN_c=33
PIN_d=35
PIN_e=37
PIN_f=32
PIN_g=36
PIN_h=38


GPIO.setmode(GPIO.BOARD)


GPIO.setup(PIN_A,GPIO.OUT)
GPIO.setup(PIN_B,GPIO.OUT)
GPIO.setup(PIN_C,GPIO.OUT)
GPIO.setup(PIN_D,GPIO.OUT)
GPIO.setup(PIN_E,GPIO.OUT)
GPIO.setup(PIN_F,GPIO.OUT)
GPIO.setup(PIN_G,GPIO.OUT)
GPIO.setup(PIN_H,GPIO.OUT)
GPIO.setup(PIN_a,GPIO.OUT)
GPIO.setup(PIN_b,GPIO.OUT)
GPIO.setup(PIN_c,GPIO.OUT)
GPIO.setup(PIN_d,GPIO.OUT)
GPIO.setup(PIN_e,GPIO.OUT)
GPIO.setup(PIN_f,GPIO.OUT)
GPIO.setup(PIN_g,GPIO.OUT)
GPIO.setup(PIN_h,GPIO.OUT)




GPIO.output(PIN_A,GPIO.LOW)
GPIO.output(PIN_B,GPIO.LOW)
GPIO.output(PIN_C,GPIO.LOW)
GPIO.output(PIN_D,GPIO.LOW)
GPIO.output(PIN_E,GPIO.LOW)
GPIO.output(PIN_F,GPIO.LOW)
GPIO.output(PIN_G,GPIO.LOW)
GPIO.output(PIN_H,GPIO.LOW)
GPIO.output(PIN_a,GPIO.LOW)
GPIO.output(PIN_b,GPIO.LOW)
GPIO.output(PIN_c,GPIO.LOW)
GPIO.output(PIN_d,GPIO.LOW)
GPIO.output(PIN_e,GPIO.LOW)
GPIO.output(PIN_f,GPIO.LOW)
GPIO.output(PIN_g,GPIO.LOW)
GPIO.output(PIN_h,GPIO.LOW)


while True:
        time.sleep(0.01)
        GPIO.output(PIN_H,GPIO.LOW)
        GPIO.output(PIN_A,GPIO.HIGH)
        GPIO.output(PIN_a,GPIO.HIGH)
        GPIO.output(PIN_b,GPIO.LOW)
        GPIO.output(PIN_c,GPIO.LOW)
        GPIO.output(PIN_d,GPIO.HIGH)
        GPIO.output(PIN_e,GPIO.HIGH)
        GPIO.output(PIN_f,GPIO.LOW)
        GPIO.output(PIN_g,GPIO.LOW)
        GPIO.output(PIN_h,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_A,GPIO.LOW)
        GPIO.output(PIN_B,GPIO.HIGH)
        GPIO.output(PIN_a,GPIO.LOW)
        GPIO.output(PIN_d,GPIO.LOW)
        GPIO.output(PIN_e,GPIO.LOW)
        GPIO.output(PIN_h,GPIO.LOW)
        time.sleep(0.01)
        GPIO.output(PIN_B,GPIO.LOW)
        GPIO.output(PIN_C,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_C,GPIO.LOW)
        GPIO.output(PIN_D,GPIO.HIGH)
        GPIO.output(PIN_a,GPIO.HIGH)
        GPIO.output(PIN_h,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_D,GPIO.LOW)
        GPIO.output(PIN_E,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_E,GPIO.LOW)
        GPIO.output(PIN_F,GPIO.HIGH)
        GPIO.output(PIN_b,GPIO.HIGH)
        GPIO.output(PIN_g,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_F,GPIO.LOW)
        GPIO.output(PIN_G,GPIO.HIGH)
        time.sleep(0.01)
        GPIO.output(PIN_G,GPIO.LOW)
        GPIO.output(PIN_H,GPIO.HIGH)
        GPIO.output(PIN_c,GPIO.HIGH)
        GPIO.output(PIN_f,GPIO.HIGH)


用树莓派控制8*8led矩阵显示红心

标签:8*8led

原文地址:http://mayuenjkxt.blog.51cto.com/2676799/1859042

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!