连接到开发板的针脚
#define dw digitalWrite
#define uint unsigned int
uint data[][10]={
{1,2,3,7,4,5,0},
{2,3,0},
{1,2,4,5,6,0},
{1,2,3,4,6,0},
{2,3,7,6,0},
{1,7,6,3,4,0},
{1,7,6,3,4,5,0},
{1,2,3,0},
{1,2,3,4,5,6,7,0},
{1,7,6,2,3,4,0}
};
bool flag = true;
uint p = 0;
//点亮一位数字
void ledstart(uint n,uint k){
//判断哪一位并开启对应位数
(k%2) ? (dw(9,1),dw(10,0)) : (dw(10,1),dw(9,0));
for(uint i = 0;i<9;i++) //初始化数码管
dw(i,1);
for(uint i = 0;data[n][i]!=0;i++)
dw(data[n][i],0);
}
void setup(){
for(uint i = 0;i<12;i++){
pinMode(i,OUTPUT);
dw(i,1);
}
//关于呼吸灯的初始化
pinMode(11,OUTPUT);
dw(11,0);
}
void loop(){
for(uint i = 0;i<10;i++){
for(uint j = 0;j<10;j++){
for(uint k = 0;k<100;k++){ //含200ms延时
ledstart(i,9);delay(2);//十位
ledstart(j,10);delay(2);//个位
//呼吸灯保证五十ms延时
if(k%20==0){
analogWrite(11,p);
if(flag){
p+=5;
flag = p==255 ? false : true;
}
else{
p-=5;
flag = p==0 ? true :false;
}
}
}
}
}
}