int value;
int num;
int i;
int direct=0;
int btn1=9;
int seg7_pin[]={2,3,4,5,6,7,8};
int seg7_table[]={
~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90
};
void setup()
{
int a,b;
pinMode(btn1,INPUT);
for(a=0;a<7;a++)
{
pinMode(seg7_pin[a],OUTPUT);
}
}
void outport(char data)
{
for(i=0;i<7;i++)
{
if(data %2 ==1)
digitalWrite(seg7_pin[i],HIGH);
else
digitalWrite(seg7_pin[i],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);
}
沒有留言:
張貼留言