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