YFROBOT创客社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: AllBlue
打印 上一主题 下一主题

Arduino入门教程—拓展实验篇九 驱动单色8*8点阵

  [复制链接]

签到天数: 866 天

[LV.10]以坛为家III

跳转到指定楼层
楼主
发表于 2013-8-18 15:21:31 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
驱动单色8*8点阵

本次实验使用Arduino 控制器直接驱动一个单色的8*8点阵,所用点阵型号为LD-1088BS,如下图:


内部原理图:

实际引脚编号:

Arduino连接图:


程序所用扩文件:


例程:
[C] 纯文本查看 复制代码
/*
* Show messages on an 8x8 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/

#include <FrequencyTimer2.h>

#define SPACE { \
    {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} \
}

#define H { \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}  \
}

#define E  { \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}

#define L { \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}

#define O { \
    {0, 0, 0, 1, 1, 0, 0, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 0, 0, 1, 1, 0, 0, 0}  \
}

byte col = 0;
byte leds[8][8];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17,13, 12, 11, 10, 9, 8, 7, 6, };

// col[xx] of leds = pin yy on led matrix
int rows[8] = {pins[16], pins[15], pins[11], pins[6], pins[10], pins[4], pins[3], pins[13]};

// row[xx] of leds = pin yy on led matrix
int cols[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
  H,E,L,L,O,SPACE
};

int pattern = 0;

void setup() {
  // sets the pins as output
  for (int i = 1; i <= 16; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 8; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 8; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop() {
    pattern = ++pattern % numPatterns;
    slidePattern(pattern, 60);
}

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = patterns[pattern][i][j];
    }
  }
}

void slidePattern(int pattern, int del) {
  for (int l = 0; l < 8; l++) {
    for (int i = 0; i < 7; i++) {
      for (int j = 0; j < 8; j++) {
        leds[j][i] = leds[j][i+1];
      }
    }
    for (int j = 0; j < 8; j++) {
      leds[j][7] = patterns[pattern][j][0 + l];
    }
    delay(del);
  }
}

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    if (leds[col][7 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}


显示图片为“HELLO ”滚动显示!

Arduino直接驱动8*8点阵占用的I/O口太多,所以建议大家使用芯片驱动8*8点阵,例如74HC595或者MAX7129芯片!!

下面也为大家提供一些IC资料,有兴趣的可以研究研究~~

74HC595中文资料:
MAX7129中文资料:
MAX7129英文资料:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持1 反对反对

签到天数: 866 天

[LV.10]以坛为家III

沙发
 楼主| 发表于 2013-8-20 08:40:14 | 显示全部楼层
/ty清風Vin/yl 发表于 2013-8-19 23:34
代码有误呀==

???哪里请指出谢谢~
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

板凳
 楼主| 发表于 2013-10-16 10:04:19 | 显示全部楼层
http://blog.bsoares.com.br/arduino/ping-pong-with-8x8-led-matrix-on-arduino

程序下载:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

地板
 楼主| 发表于 2014-9-19 18:02:31 | 显示全部楼层
zjjdog3 发表于 2014-9-18 22:28
求问我这个反面5根针的怎么插? 有例程吗?

根据你的程序来接线:
  1. //Pin connected to DS of 74HC595
  2. int SER = 9;
  3. //Pin connected to ST_CP of 74HC595
  4. int RCK  = 10;
  5. //Pin connected to SH_CP of 74HC595
  6. int SRCK  = 11;
复制代码
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

5#
 楼主| 发表于 2015-4-15 20:39:09 | 显示全部楼层
xirunamd 发表于 2015-4-13 22:35
怎么弄啊,能不能详细点

SER -- 接引脚9
RCK -- 接引脚10
SRCK  接引脚11
vcc接5V
GND 接GND
这样够详细了吗?引脚可以更改,更改后对应接线也更改就可以了!
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

6#
 楼主| 发表于 2015-7-22 08:16:22 | 显示全部楼层
anjiao 发表于 2015-7-22 02:23
我补一个驱动5针LED的例子

[mw_shl_code=cpp,true]#include

图片没有上传,建议将包含的库文件一并上传分享!
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

7#
 楼主| 发表于 2015-12-11 14:57:08 | 显示全部楼层
a1220529673 发表于 2015-12-11 09:48
全亮了,求破。。。。。

你检查下连接电路呢,这代码应该不会有问题的,都是试过的!
回复 支持 反对

使用道具 举报

签到天数: 866 天

[LV.10]以坛为家III

8#
 楼主| 发表于 2016-6-14 09:49:47 | 显示全部楼层
74865132` 发表于 2016-6-11 23:08
为什么我仿真显示不出来,是缺少库文件还是没设置好[/img]

仿真软件没用玩过
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|联系我们|YFROBOT ( 苏ICP备20009901号-2  

GMT+8, 2024-5-17 16:04 , Processed in 0.047289 second(s), 23 queries .

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表