char seg7_table[] = {
~0xc0, ~0xf9, ~0xa4, ~0xb0, ~0x99, ~0x92, ~0x82, ~0xf8, ~0x80, ~0x90,
~0x88, ~0x83, ~0xc6,~0xa1, ~0x86, ~0x8e
};
byte weight[] = {8, 4, 2, 1};
byte seg7_pin[] = {2, 3, 4, 5, 6, 7, 8};
byte dip_sw[] = {9, 10, 11, 12};
byte number;
//----------------------------------------------------
void setup()
{
for (int i = 0; i < 7; i++)
{
pinMode(seg7_pin[i], OUTPUT);
}
for(int j=0;j<4;j++)
{
pinMode(dip_sw[j],INPUT);
}
Serial.begin(9600);
}
void tx(byte rx)
{
for (int x = 0; x < 7; x++)//只是讓他跑七段
{
if (rx % 2 == 1)
{
digitalWrite(seg7_pin[x], HIGH);
}
else
{
digitalWrite(seg7_pin[x], LOW);
}
rx = rx / 2;
}
}
void loop()
{
number = 0;
for ( int i = 0; i < 4; i++)
{
if (digitalRead(dip_sw[i]) == HIGH)
{
number = number + weight[i];Serial.println(number);
}
}
tx(seg7_table[number]);
}
沒有留言:
張貼留言