点阵的16个引脚分别代表着8列和8行,通过指定哪一列和哪一行的引脚为高低电平,实现点亮,比如点亮最左上方,看上图左上方行和列是那两个引脚,圆圈内数字表示引脚,行是9,列是13,所以点亮最左上方,只需要让13引脚高电平,9引脚低电int col[8] = {7,2,A0,4,12,A1,11,A3};
int row[8] = {3,A5,A4,6,A2,5,1,0};
int appear[8][8] = {{0,0,0,0,0,0,0,0},//爱心
{0,1,0,0,0,0,1,0},
{1,0,1,0,0,1,0,1},
{1,0,0,1,1,0,0,1},
{0,1,0,0,0,0,1,0},
{0,0,1,0,0,1,0,0},
{0,0,0,1,1,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(col[i],OUTPUT);
digitalWrite(row[i],LOW);//把行设为高电压,把列设为低电压,避免接通就亮。
digitalWrite(col[i],HIGH);
}
}
void loop() {
draw();
}
void draw(){
for(int i = 0;i < 8;i++){
for(int j = 0;j < 8;j++){
if(appear[i][j] == 1){//逐行逐列检查是否等于1。
digitalWrite(col[i],LOW);//从数组为1的位置开始点亮
digitalWrite(row[j],HIGH);
delay(1);
digitalWrite(row[j],LOW);//把数组为1后面位置都LED熄灭
digitalWrite(col[i],HIGH);
}
}
}
}
平即可点亮,可使用万用表测试电路导通方法点亮 |