int in1_pin = 10;
int in2_pin = 11;
int buzzer_pin = 12;
int key1_pin = A0;
int key2_pin = A1;
int key3_pin = A2;
int seg7_pin[] = {9, 8, 7, 6, 5, 4, 3, 2};
int seg7_table[]={~0x8E,~0x92,~0x83};
int buzzer = 12;
int mode=10;
void setup()
{
pinMode(buzzer_pin,OUTPUT);
pinMode(in1_pin,OUTPUT);
pinMode(in2_pin,OUTPUT);
for(int i=0;i<7;i++)
{
pinMode(seg7_pin[i],OUTPUT);
}
}
//--------------------------------
void outport(byte data)
{
for(int j=0;j<7;j++)
{
if(data%2==1)
digitalWrite(seg7_pin[j],HIGH);
else
digitalWrite(seg7_pin[j],LOW);
data=data/2;
}
}
void loop()
{
if(digitalRead(key1_pin)==0 && mode!=1)
{
mode=1;
outport(seg7_table[0]);
digitalWrite(in1_pin,HIGH);
digitalWrite(in2_pin,LOW);
tone(buzzer,500,300);
}
else if(digitalRead(key2_pin)==0 && mode!=2)
{
mode=2;
outport(seg7_table[1]);
digitalWrite(in1_pin,LOW);
digitalWrite(in2_pin,LOW);
tone(buzzer_pin,500,1000);
}
else if(digitalRead(key3_pin)==0 && mode!=3)
{
mode=3;
outport(seg7_table[2]);
digitalWrite(in1_pin,LOW);
digitalWrite(in2_pin,HIGH);
tone(buzzer_pin,500,300); delay(400);
tone(buzzer_pin,500,300);
}
}
沒有留言:
張貼留言