int buzzer=13;
int led_pin[]={14,15,16,17,18,19};
int seg7_pin[]={2,3,4,5,6,7,8};
int scan_line[]={9,10,11,12};
int seg7_table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};
int i;
int j;
int k;
int times=0;
void setup()
{
int a;
int b;
pinMode(buzzer,OUTPUT);
for(b=0;b<6;b++)
{
pinMode(led_pin[b],OUTPUT);
}
for(a=0;a<7;a++)
{
pinMode(seg7_pin[a],OUTPUT);
}
}
void outport(byte data)
{
int x;
for(x=0;x<7;x++)
{
if(data%2==1)
digitalWrite(seg7_pin[x],HIGH);
else
digitalWrite(seg7_pin[x],LOW);
data=data/2;
}
}
//---------------------------------------
void initial()
{
for(i=0;i<4;i++)
{
for(j=0;j<50;j++)
{
outport(seg7_table[0]);digitalWrite(scan_line[0],HIGH);delay(5); digitalWrite(scan_line[0],LOW);
outport(seg7_table[8]);digitalWrite(scan_line[1],HIGH);delay(5); digitalWrite(scan_line[1],LOW);
outport(seg7_table[0]);digitalWrite(scan_line[2],HIGH);delay(5); digitalWrite(scan_line[2],LOW);
outport(seg7_table[7]);digitalWrite(scan_line[3],HIGH);delay(5); digitalWrite(scan_line[3],LOW);
}
delay(1500);
}
}
//---------------------------------------
void led()
{
int ii;
for(ii=0;ii<3;ii++)
{
digitalWrite(led_pin[0],HIGH);
digitalWrite(led_pin[1],HIGH);
digitalWrite(led_pin[2],HIGH);
digitalWrite(led_pin[3],HIGH);
digitalWrite(led_pin[4],HIGH);
digitalWrite(led_pin[5],HIGH);
delay(1000);
digitalWrite(led_pin[0],LOW);
digitalWrite(led_pin[1],LOW);
digitalWrite(led_pin[2],LOW);
digitalWrite(led_pin[3],LOW);
digitalWrite(led_pin[4],LOW);
digitalWrite(led_pin[5],LOW);
delay(1000);
}
}
//--------------------------------------
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);
led();
}
}
沒有留言:
張貼留言