int seg7_pin[]={2,3,4,5,6,7,8};
char seg7_table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};
int scan_line[]={9,10,11,12};
int i,j,k;
int times=0;
int buzzer=13;
//----------------------------
void setup()
{
pinMode(buzzer,OUTPUT);
for(i=0;i<7;i++)
{
pinMode(seg7_pin[i],OUTPUT);
}
for(j=0;j<3;j++)
{
pinMode(scan_line[j],OUTPUT);
}
}
//-----------------------------
void outport(char data)
{
for(k=0;k<7;k++)
{
if(data % 2==1)
digitalWrite(seg7_pin[k],HIGH);
else
digitalWrite(seg7_pin[k],LOW);
data =data /2;
}
}
//-----------------------------
void initial()
{
for(i=0;i<3;i++)
{
for(j=0;j<50;j++)
{
outport(seg7_table[0]);//0
digitalWrite(scan_line[0],HIGH),delay(5);digitalWrite(scan_line[0],LOW);
outport(seg7_table[8]);//8
digitalWrite(scan_line[1],HIGH),delay(5);digitalWrite(scan_line[1],LOW);
outport(seg7_table[0]);//0
digitalWrite(scan_line[2],HIGH),delay(5);digitalWrite(scan_line[2],LOW);
outport(seg7_table[7]);//7
digitalWrite(scan_line[3],HIGH),delay(5);digitalWrite(scan_line[3],LOW);
}
delay(2000);
}
}
//-----------------------------
void loop()
{
if(times==0)
{
times=1;
initial();
tone(buzzer,500,500);delay(1000);
tone(buzzer,500,500);delay(1000);
tone(buzzer,500,500);delay(1000);
}
}
沒有留言:
張貼留言