#define key1 A0
#define key2 A1
int keyval=0;
int i;
int j;
const char num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
const int seg[]={2,3,4,5,6,7,8,9};
void setup()
{
for(i=0;i<8;i++)
{
pinMode(seg[i],OUTPUT);
}
pinMode(key1,INPUT);
pinMode(key2,INPUT);
}
void loop()
{
if(digitalRead(key1)==0)
{
delay(20);
while(digitalRead(key1)==0);
keyval++;
if(keyval>9) keyval=0;
output(num[keyval]);
}
if(digitalRead(key2)==0)
{
delay(20);
while(digitalRead(key2)==0);
keyval--;
if(keyval<0) keyval=9;
output(num[keyval]);
}
delay(20);
}
void output(byte data)
{
for(i=0;i<8;i++)
digitalWrite(seg[i],bitRead(~data,i));
}
沒有留言:
張貼留言