查看: 5344|回复: 0

树莓派驱动8*8LED点阵

[复制链接]
  • TA的每日心情
    开心
    2015-7-28 20:04
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2015-4-28 14:09:54 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 二进制病毒 于 2015-4-28 14:12 编辑

         这里只是为了练习GPIO的使用,没有加任何的译码设备,也没加任何的放大设备,直接用树莓派的16个gpio引脚,连接一个8*8LED点阵的16个引脚,考虑到树莓派所能提供的电流不能太大,所以统一在点阵的8个阳极各加了一个1kΩ的电阻
        8*8电阻的16个引脚,8个阳极,8个阴极,我们可以第一为R1~R8、C1~C8(考虑到点阵是方形的,所以不去区分行列,只区分阴阳,上面的R/C和“阴/阳”的对应关系,请根据实际共阴还是共阳区分清楚)
        下面几段核心的python代码
        管脚对应关系,这里和gpio与8*8点阵的链接有关
    1. rs = [21, 20, 16, 12, 25, 24, 23, 18] #R1:13 R2:3 R3:4 R4:10 R5:6 R6:11 R7:15 R8:16
    2. cs = [26, 19, 13, 6, 5, 22, 27, 17] #C1:5 C2:2 C3:7 C4:1 C5:12 C6:8 C7:14 C8:9
    复制代码
    字模,八行,N列
    1. #Hello World
    2. vhws = [
    3.   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
    4.   [0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0],
    5.   [0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0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,1,1,1,0,0,0,0,0],
    11. ]
    复制代码
    从字模里拿一个8*8数组
    1. isRig = 1
    2. vhwi = 0
    3. def hwv():
    4.   global isRig
    5.   global vhwi
    6.   l = len(vhws[0])
    7.   if isRig > 0:
    8.     vhwi += 1
    9.   else:
    10.     vhwi -= 1
    11.   if vhwi >= (l - 8):
    12.     isRig = 0
    13.   if vhwi <= 0:
    14.     isRig = 1  
    15.   r = []
    16.   for i in range(0, len(vhws)):
    17.     j = vhwi
    复制代码

    详细的代码请看我的博客:http://www.jiangkunlun.com/2015/04/led_8/
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 11:32 , Processed in 0.113466 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.