int i;
int j;
int count=0;
int number;
int KeyData;
int numKeys=0;
const int debounceDelay=20;
unsigned long time=0;
const byte num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
const int seg[]={6,7,8,9,10,11,12}; //abcdefg
const int digit[]={2,3,4,5}; //D0-D3
const int sw=14;
void setup()
{
pinMode(sw,INPUT);
digitalWrite(sw,HIGH);
for(i=0;i<8;i++)
pinMode(seg[i],OUTPUT);
for(i=0;i<4;i++)
{
pinMode(digit[i],OUTPUT);
digitalWrite(digit[i],0);
}
}
void loop()
{
KeyData=digitalRead(sw);
if(KeyData==LOW)
{
delay(debounceDelay);
while(digitalRead(sw)==LOW)
;
numKeys++;
}
number=count;
for(i=3;i>=0;i--)
{
for(j=0;j<7;j++)
{
digitalWrite(seg[j],bitRead(~num[number%10],j));
}
digitalWrite(digit[i],1);
delay(5);
digitalWrite(digit[i],0);
number=number/10;
if(millis()-time>=1000)
{
time=millis();
if(numKeys%2==0)
{
count++;
if(count>9999)
count=0;
}
else
{
count--;
if(count<0)
count=9999;
}
}
}
}
沒有留言:
張貼留言