int dip[]={2,3,4,5};
int weight[]={8,4,2,1};
char seg7table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90,
~0x88,~0x83,~0xc6,~0xa1,~0x86,~0x8e};
int seg7[]={6,7,8,9,10,11,12};
int i;
int j;
int number;
int value;
void setup()
{
for(i=0;i<7;i++)
{
pinMode(seg7[i],OUTPUT);
}
for(j=0;j<4;j++)
{
pinMode(dip[j],INPUT);
}
}
//---------------------------------------
void outport(char data)
{
for(j=0;j<7;j++)
{
if(data %2 ==1)
digitalWrite(seg7[j],HIGH);
else
digitalWrite(seg7[j],LOW);
data=data/2;
}
}
//-----------------------------------------
void loop()
{
number=0;
for(i=0;i<4;i++)
{
value=digitalRead(dip[i]);
if(value==HIGH)
number=number+weight[i];
}
outport(seg7table[number]);
}
沒有留言:
張貼留言