int btn1=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 value;
int num;
int direct=0;
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()
{
value=digitalRead(btn1);
if(value==LOW)
{
delay(1000);
while(digitalRead(btn1)==LOW);
direct=direct^1;
}
if(direct==0)
{
if(num==9)
num=0;
else
num++;
}
else
{
if(num==0)
num=9;
else
num--;
}
outport(seg7_table[num]);
delay(1000);
}
沒有留言:
張貼留言