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