1
您可以在ElectroPeak 的官方网站上阅读本教程和其他精彩教程
在本教程中,您将学习如何使用带有 IC MAX7219 的 8×8 点阵 LED 模块。最后,您将能够轻松地、固定或滚动地在一个或多个点阵上显示任何形状或文本,仅使用 4 个 arduino 数字引脚。
ot Matrix LED 8×8 是一个 LED 阵列,您可以在其上显示特定的数字、字母和形状。点阵由行数和列数表示。最受欢迎的点阵类型是其 8×8 类型,它提供 8 行 8 列的 64 个 LED。
要简单地控制8×8点阵,你应该将每一行和每一列连接到一个数字引脚,这意味着你需要16个数字引脚!所以这不是一个正确的方法。
要控制点阵,有一些基于 MAX72xx ICS 的模块需要连接到 4 个数字引脚而不是 16 个。您还可以将多个点阵(最多 8 个)相互连接,而无需任何额外的引脚并将它们级联。
要将点阵连接到Arduino,只需将Vcc和GND引脚连接到5V和GND Arduino,点阵的DIN、CS和CLK引脚可以连接到arduino的任何数字引脚。
点阵和 Arduino 有各种库。Ledcontrol和MaxMatrix库是两个最常见的库,它们具有相同的结构。
现在将以下代码上传到您的 Arduino 板上。
/*
8x8 Dot Matrix w/ MAX7219
modified on 7 March 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include int DIN = 7;
int CLK = 6;
int CS = 5;
int maxInUse = 1;
byte buffer[20];
char text[] = "a";
MaxMatrix m(DIN, CS, CLK, maxInUse);
void setup() {
m.init();
m.setIntensity(8);
}
void loop() {
m.setDot(0, 7, true);
m.setDot(0, 7, true);
delay(1000);
m.setDot(7, 0, true);
delay(1000);
m.setColumn(3, B11110000);
delay(1000);
m.setColumn(4, B00001111);
delay(1000);
m.clear();
delay(1000);
}
该库的一些最重要的功能如下:
要在点阵上显示您的特定形状,只需将 LED 灯图案转换为位串即可。为此,您可以从此类在线工具中获得帮助。设计您的形状并将生成的代码复制到 Arduino,然后将其上传到您的板上。
/*
8x8 Dot Matrix w/ MAX7219
modified on 7 March 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include int DIN = 7;
int CLK = 6;
int CS = 5;
int maxInUse = 1;
MaxMatrix m(DIN, CS, CLK, maxInUse);
byte poker[] = {8, 8,
0xff,
0x81,
0xa5,
0xa1,
0xa1,
0xa5,
0x81,
0xff
};
byte smile[] = {8, 8,
0xff,
0x81,
0xb5,
0xa1,
0xa1,
0xb5,
0x81,
0xff
};
byte sad[] = {8, 8,
0xff,
0x81,
0xb5,
0x91,
0x91,
0xb5,
0x81,
0xff
};
byte kiss[] = {8, 8,
0xff,
0x81,
0xb5,
0xb1,
0xb1,
0xb5,
0x81,
0xff
};
void setup() {
m.init();
m.setIntensity(8);
}
void loop() {
m.writeSprite(0, 0, smile);
delay(1000);
m.clear();
m.writeSprite(0, 0, poker);
delay(1000);
m.clear();
m.writeSprite(0, 0, sad);
delay(1000);
m.clear();
m.writeSprite(0, 0, kiss);
delay(1000);
for (int i = 0; i < 8; i++) {
m.shiftLeft(false, false);
delay(300);
}
m.clear();
}
您还可以通过此方法创建和显示数字和字母。
要插入常见的数字、字母和符号,您可以使用以下字符串和函数:
#include byte buffer[10];
PROGMEM const unsigned char CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // < 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // = 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};
void printCharWithShift(char c, int shift_speed) {
if (c < 32) return;
c -= 32;
memcpy_P(buffer, CH + 7 * c, 7);
m.writeSprite(32, 0, buffer);
m.setColumn(32 + buffer[0], 0);
• for (int i = 0; i < buffer[0] + 1; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}
void printStringWithShift(char* s, int shift_speed) {
while (*s != 0) {
printCharWithShift(*s, shift_speed);
s++;
}
}
void printString(char* s)
{
int col = 0;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s - 32;
memcpy_P(buffer, CH + 7 * c, 7);
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}
点阵模块的一个有趣特性是能够连接多个(最多 8 个)模块并在其上显示级联信息。
为此,将第一个模块的 Dout 连接到下一个模块的Din ,并将具有相同名称的其他引脚相互连接。
现在将以下代码上传到您的 Arduino 并查看结果。
/*
8x8 Dot Matrix w/ MAX7219
modified on 7 March 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include int DIN = 7;
int CLK = 6;
int CS = 5;
int maxInUse = 2;
MaxMatrix m(DIN, CS, CLK, maxInUse);
byte pakman[] = {8, 8, 0x1c, 0x22, 0x41, 0x49, 0x55, 0x22, 0x00, 0x08};
void setup() {
m.init();
m.setIntensity(2);
}
void loop(){
m.writeSprite(0, 0, pakman);
delay(300);
for (int i = 0; i < 8; i++) {
m.shiftRight(false, true);
delay(300);
}
m.clear();
}
笔记
不要忘记您只是直接对第一个模块进行编程。
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !