YFROBOT创客社区

标题: Arduino入门教程—拓展实验篇九 驱动单色8*8点阵 [打印本页]

作者: AllBlue    时间: 2013-8-18 15:21
标题: Arduino入门教程—拓展实验篇九 驱动单色8*8点阵
驱动单色8*8点阵

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

[attach]452[/attach]
内部原理图:
[attach]451[/attach]
实际引脚编号:
[attach]456[/attach]
Arduino连接图:
[attach]450[/attach]

程序所用扩文件:

[attach]449[/attach]


例程:
[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, 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[j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[j] = patterns[pattern][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] = 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中文资料:[attach]492[/attach]
MAX7129中文资料:[attach]494[/attach]
MAX7129英文资料:[attach]493[/attach]



作者: /ty清風Vin/yl    时间: 2013-8-19 23:34
代码有误呀==
作者: AllBlue    时间: 2013-8-20 08:40
/ty清風Vin/yl 发表于 2013-8-19 23:34
代码有误呀==

???哪里请指出谢谢~
作者: xin8236    时间: 2013-10-13 20:56
5555,我的YFrobot套件中的单色点阵型号是LD-1088BHG,上下各12个针脚,怎么安啊-_-#
作者: AllBlue    时间: 2013-10-16 10:04
http://blog.bsoares.com.br/arduino/ping-pong-with-8x8-led-matrix-on-arduino
[attach]624[/attach]
程序下载:
[attach]625[/attach]
作者: dreamdesignerj    时间: 2014-1-7 21:11
不错不错,学习一下
作者: zjjdog3    时间: 2014-9-18 22:28
求问我这个反面5根针的怎么插? 有例程吗?
[attach]881[/attach]
作者: AllBlue    时间: 2014-9-19 18:02
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;
复制代码

作者: limhy1990    时间: 2014-11-2 00:08
8*8点阵 反面5根针的 不明白 怎么弄。。。求救。。

作者: xirunamd    时间: 2015-4-13 22:35
AllBlue 发表于 2014-9-19 18:02
根据你的程序来接线:

怎么弄啊,能不能详细点
作者: AllBlue    时间: 2015-4-15 20:39
xirunamd 发表于 2015-4-13 22:35
怎么弄啊,能不能详细点

SER -- 接引脚9
RCK -- 接引脚10
SRCK  接引脚11
vcc接5V
GND 接GND
这样够详细了吗?引脚可以更改,更改后对应接线也更改就可以了!
作者: lexilin    时间: 2015-6-29 02:19
我也不懂这个五根针要怎么连啊?sketch貌似是用于自己连接64个led的,而不是针对这个led display的。。。能不能详细说明一下要怎么用五根针的连线做到hello的效果?
作者: anjiao    时间: 2015-7-22 02:23
我补一个驱动5针LED的例子
D:\Documents\Bluetooth Folder\IMG_20150722_021849.jpg
[C++] 纯文本查看 复制代码
#include <FrequencyTimer2.h>

#define NOP() do { __asm__ __volatile__ ("nop"); } while (0)
#define _countof(a)                (sizeof(a) / sizeof(a[0]))

class HC595LED
{
public:
        HC595LED(int ser, int rck, int srck)
        {
                _SER = ser;
                _RCK = rck;
                _SRCK = srck;
        }
       
        void begin()
        {
                pinMode(_SER, OUTPUT);
                pinMode(_RCK, OUTPUT);
                pinMode(_SRCK, OUTPUT);

                digitalWrite(_SER, LOW);
                digitalWrite(_RCK, LOW);
                digitalWrite(_SRCK, LOW);
        }

        void displayRow(uint8_t nRow, uint8_t data)
        {
                nRow = 7 - nRow;

                for(int i = 0; i < 8; i++)
                        _rowEnable(i == nRow);
                for(int i = 7; i >= 0; i--) {
                        _colEnable(bitRead(data, i));
                }
                flushScreen();
        }

        void clear()
        {
                for(int i = 0; i < 8; i++)
                        _rowEnable(false);
                for(int i = 0; i < 8; i++)
                        _colEnable(false);
        }

        void writeItem(bool bHigh)
        {
                digitalWrite(_SER, bHigh ? HIGH : LOW);
                _flushItem();
        }

        void flushScreen()
        {
                digitalWrite(_RCK, HIGH);
                NOP();
                NOP();
                digitalWrite(_RCK, LOW);
        }
private:
        void _rowEnable(bool bEnable)
        {
                writeItem(!bEnable);
        }
        void _colEnable(bool bEnable)
        {
                writeItem(bEnable);
        }

        void _flushItem()
        {
                digitalWrite(_SRCK, HIGH);
                NOP();
                NOP();
                digitalWrite(_SRCK, LOW);
        }

private:
        int _SER;
        int _RCK;
        int _SRCK;
};

///////////////////////////////////////////////////////////////////////

//Pin connected to DS of 74HC595
const int SER_PIN = 8;
//Pin connected to ST_CP of 74HC595
const int RCK_PIN = 9;
//Pin connected to SH_CP of 74HC595
const int SRCK_PIN = 10;

HC595LED led(SER_PIN, RCK_PIN, SRCK_PIN);

PROGMEM const char SPACE[] =
{
        0b00000000,
        0b00000000,
        0b00000000,
        0b00000000,
        0b00000000,
        0b00000000,
        0b00000000,
        0b00000000,
};
PROGMEM const char H[] =
{
        0b01000010,
        0b01000010,
        0b01000010,
        0b01111110,
        0b01000010,
        0b01000010,
        0b01000010,
        0b01000010,
};
PROGMEM const char E[] =
{
        0b01111110,
        0b01000000,
        0b01000000,
        0b01111110,
        0b01000000,
        0b01000000,
        0b01000000,
        0b01111110,
};
PROGMEM const char L[] =
{
        0b01000000,
        0b01000000,
        0b01000000,
        0b01000000,
        0b01000000,
        0b01000000,
        0b01000000,
        0b01111110,
};
PROGMEM const char O[] =
{
        0b00011000,
        0b00100100,
        0b01000010,
        0b01000010,
        0b01000010,
        0b01000010,
        0b00100100,
        0b00011000,
};

const char * const arrShowData[] = {H, E, L, L, O, SPACE};

char arrShowBuffer[] =
{
        0, 0, 0, 0, 0, 0, 0, 0,
};
void display()
{
        static int s_nIndex = 0;

        led.displayRow(s_nIndex, arrShowBuffer[s_nIndex]);

        s_nIndex++;
        s_nIndex %= 8;
}

void setup()
{
        led.begin();
    Serial.begin(9600);

    delay(1000);
        led.clear();

        FrequencyTimer2::disable();
        FrequencyTimer2::setPeriod(2000);
        FrequencyTimer2::setOnOverflow(display);
}

void loop()
{
        int s_nIndex = 0;

        while(true) {
                noInterrupts();
                memcpy_PF(arrShowBuffer, (uint_farptr_t)arrShowData[s_nIndex], sizeof(arrShowBuffer));
                interrupts();

                s_nIndex++;
                s_nIndex %= _countof(arrShowData);

                delay(2000);
        }
}


作者: AllBlue    时间: 2015-7-22 08:16
anjiao 发表于 2015-7-22 02:23
我补一个驱动5针LED的例子

[mw_shl_code=cpp,true]#include

图片没有上传,建议将包含的库文件一并上传分享!
作者: anjiao    时间: 2015-7-22 21:30
[attach]1033[/attach]
这是连线方法和动行效果


作者: a1220529673    时间: 2015-12-11 09:48
AllBlue 发表于 2013-8-20 08:40
???哪里请指出谢谢~

全亮了,求破。。。。。
作者: AllBlue    时间: 2015-12-11 14:57
a1220529673 发表于 2015-12-11 09:48
全亮了,求破。。。。。

你检查下连接电路呢,这代码应该不会有问题的,都是试过的!
作者: 74865132`    时间: 2016-6-11 23:08
为什么我仿真显示不出来,是缺少库文件还是没设置好[img]C:\Users\Administrator\DesktopC:\Users\Administrator\Desktop[/img]
作者: 74865132`    时间: 2016-6-11 23:10
图如下。。。。
作者: AllBlue    时间: 2016-6-14 09:49
74865132` 发表于 2016-6-11 23:08
为什么我仿真显示不出来,是缺少库文件还是没设置好[/img]

仿真软件没用玩过
作者: 葳蕤礼赞    时间: 2016-7-30 20:04
Arduino:1.6.10 (Windows 8), 开发板:"Arduino/Genuino Uno"

C:\Users\dell-xy\Desktop\sketch_jul30a\sketch_jul30a.ino:1:29: fatal error: FrequencyTimer2.h: No such file or directory

#include <FrequencyTimer2.h>

                             ^

compilation terminated.

exit status 1
为开发板 Arduino/Genuino Uno 编译时出错。

我是五针的,出现这个问题
作者: bearchen    时间: 2016-10-7 18:24
Arduino:1.6.8 Hourly Build 2016/02/16 05:07 (Windows 7), 开发板:"Arduino/Genuino Uno"

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `__vector_7'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2:nOverflow'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::setOnOverflow(void (*)())'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::setPeriod(unsigned long)'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::enabled'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::getPeriod()'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::enable()'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

libraries\FrequencyTimer2\FrequencyTimer2.cpp.o: In function `__vector_7':

C:\Users\Administrator\Documents\Arduino\libraries\FrequencyTimer2/FrequencyTimer2.cpp:42: multiple definition of `FrequencyTimer2::disable()'

sketch\FrequencyTimer2.cpp.o:sketch/FrequencyTimer2.cpp:42: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
编译有误。

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

作者: innovater    时间: 2017-2-10 18:02
有待研究
作者: innovater    时间: 2017-2-10 20:52
正在研究74HC595
作者: tiantianyouyou    时间: 2019-5-2 07:56
Arduino入门教程—拓展实验篇九 驱动单色8*8点阵
作者: tiantianyouyou    时间: 2019-5-2 08:02
MAX7219英文资料,这个好
作者: tiantianyouyou    时间: 2019-5-2 08:03
不错不错,学习一下
作者: wzcc    时间: 2019-11-5 21:40
怎么定义脚位置的?
作者: tiantianyouyou    时间: 2019-11-12 12:03
不错不错,学习一下




欢迎光临 YFROBOT创客社区 (http://www.yfrobot.com.cn/) Powered by Discuz! X3.1