一个丑丑的 8*8LED点阵(16/18引脚)
本次实验没有使用寄存器所以需要大量的杜邦线
同理,8*8至少16的引脚,Mega是最适合的
8* 8 LED点阵共由 64 个发光二极管组成,每个发光二极管是放置在行线和列线的交叉点上,且当对应的行为 1 电平,列置 0 电平,该坐标二极管就亮;
同理点亮一行:第 1 脚要接高电平,【A,B,C,D,E,F,G,H 】接低电平,第一行点亮;反之,第 a 脚接低电平,而【】1、2、3、4、5、6、7、8】接高电平,第一列点亮;
PS:行所接的是二极管的阳极,为高电平,列所接的是二极管的阴极极,为低电平
18引脚
平面示意图
16引脚
对于对称分布的,16引脚平面引脚图
PS:部分元件的实际引脚可能会很乱,这个具体看元件的实际引脚
方便来说,我焊接在板子上,面包板会比较松
小建议
接线的时候,一行和一列的按一定顺序接Mega(具体可以看代码定义)
PS:上图大概模拟接线顺序,并非本次实验接线图
int Row[] = {30, 31, 32, 33, 34, 35, 36, 37};//定义行引脚
int Column[] = {22, 23, 24, 25, 26, 27, 28, 29};//定义列引脚
unsigned char Light[8][8] = //'全亮'
{
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
};
unsigned char Dark[8][8] = //'全灭'
{
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,
};
void setup() {
// 矩阵代码运行一次:
for(int i = 0; i < 8; i++)
{
pinMode(Row[i], OUTPUT);//输出模式
pinMode(Column[i], OUTPUT);//输出模式
}
}
void loop() {
//主代码循环运行:
for(int i = 0; i< 100; i++)
{
Display(Light);
}
for(int i = 0; i< 100; i++)
{
Display(Dark);
}
}
void Display(unsigned char lattice[8][8])//显示函数
{
for(int r = 0; r < 8; r++)
{
digitalWrite(Row[r], LOW);
for(int c = 0; c < 8; c++)
{
digitalWrite(Column[c], lattice[r][c]);
}
delay(1);
Clear();
}
}
void Clear()//清除函数
{
for(int i = 0; i < 8; i++)
{
digitalWrite(Row[i], HIGH);
digitalWrite(Column[i], LOW);
}
}
编译上传成功后,LED灯开始一闪一闪
这部分是绘制面板,你可以想象你想绘制的图案(‘1’代表亮灯,‘0’为熄灭)
例如:
unsigned char bigheart[8][8] = //'爱心'
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
};
int Row[] = {30, 31, 32, 33, 34, 35, 36, 37};//定义行引脚
int Column[] = {22, 23, 24, 25, 26, 27, 28, 29};//定义列引脚
unsigned char bigheart[8][8] = //'大心'
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
};
unsigned char smallheart[8][8] = //'小心'
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 1, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1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
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,
};
unsigned char U[8][8] = //'U'
{
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 1, 0, 0, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 1, 1,
0, 0, 1, 1, 1, 1, 0, 0,
};
void setup() {
// 矩阵代码运行一次:
for(int i = 0; i < 8; i++)
{
pinMode(Row[i], OUTPUT);//输出模式
pinMode(Column[i], OUTPUT);//输出模式
}
}
void loop() {
//主代码循环运行:
for(int i = 0; i< 100; i++)
{
Display(I);
}
for(int i = 0; i< 100; i++)
{
Display(L);
}
for(int i = 0; i< 100; i++)
{
Display(O);
}
for(int i = 0; i< 100; i++)
{
Display(V);
}
for(int i = 0; i< 100; i++)
{
Display(E);
}
for(int i = 0; i< 100; i++)
{
Display(U);
}
for(int i = 0; i< 100; i++)
{
Display(bigheart);
}
for(int i = 0; i < 100; i++)
{
Display(smallheart);
}
for(int i = 0; i< 100; i++)
{
Display(bigheart);
}
for(int i = 0; i < 100; i++)
{
Display(smallheart);
}
for(int i = 0; i < 100; i++)
{
Display(bigheart);
}
}
void Display(unsigned char lattice[8][8])//显示函数
{
for(int r = 0; r < 8; r++)
{
digitalWrite(Row[r], LOW);
for(int c = 0; c < 8; c++)
{
digitalWrite(Column[c], lattice[r][c]);
}
delay(1);
Clear();
}
}
void Clear()//清除函数
{
for(int i = 0; i < 8; i++)
{
digitalWrite(Row[i], HIGH);
digitalWrite(Column[i], LOW);
}
}
实物效果