int seg7_pin[]={2,3,4,5,6,7,8};
int seg7_table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};
int i;
int j;
int k;
int num;
int value1;
int value2;
int btn1=9;
int btn2=10;
int buzzer=11;
void setup()
{
pinMode(buzzer,OUTPUT);
pinMode(btn1,INPUT);
pinMode(btn2,INPUT);
for(i=0;i<7;i++)
{
pinMode(seg7_pin[i],OUTPUT);
}
}
//---------------------------
void outport(char data)
{
for(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()
{
value1=digitalRead(btn1);
{
if(value1==LOW)
{
delay(1000);
while(digitalRead(btn1)==LOW);
tone(buzzer,500,500);
delay(1000);
if(num==9)
num=0;
else
num++;
}
}
value2=digitalRead(btn2);
{
if(value2==LOW)
{
delay(1000);
while(digitalRead(btn2)==LOW);
tone(buzzer,500,500);
delay(1000);
if(num==0)
num=9;
else
{
num--;
}
}
}
outport(seg7_table[num]);
}
沒有留言:
張貼留言