int seg7_pin[]={2,3,4,5,6,7,8};
int dip_sw[]={9,10,11,12};
int weight[]={8,4,2,1};
int seg7_table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90,
~0x88,~0x8c,~0xc6,~0xa1,~0x86,~0x8e};
int i;
int number;
int value;
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()
{
number=0;
for(i=0;i<4;i++)
{
value=digitalRead(dip_sw[i]);
if(value==HIGH)
number=number+weight[i];
}
outport(seg7_table[number]);
}
沒有留言:
張貼留言