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]={
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000}; //9
const byte show_year[4]=
{
B10100100, //2
B11000000, //0
B10100100, //2
B11111001, //1
};
const byte show_mon_day[4]=
{
B11000000, //0
B10000000, //8
B11000000, //0
B11111001, //1
};
const int seg[]={2,3,4,5,6,7,8,9}; //abcdefgp
const int digit[]={10,11,12,13}; //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],LOW);
}
}
void loop()
{
KeyData=digitalRead(sw);
if(KeyData==LOW)
{
delay(debounceDelay);
while(digitalRead(sw)==LOW)
;
numKeys++;
}
number=count;
for(i=3;i>=0;i--)
{
if(numKeys%3==0)
{
for(j=0;j<8;j++)
{
if(bitRead(num[number%10],j))
digitalWrite(seg[j],LOW);
else
digitalWrite(seg[j],HIGH);
}
}
else if(numKeys%3==1)
{
for(j=0;j<8;j++)
{
if(bitRead(show_year[i],j))
digitalWrite(seg[j],LOW);
else
digitalWrite(seg[j],HIGH);
}
}
else if(numKeys%3==2)
{
for(j=0;j<8;j++)
{
if(bitRead(show_mon_day[i],j))
digitalWrite(seg[j],LOW);
else
digitalWrite(seg[j],HIGH);
}
}
digitalWrite(digit[i],HIGH);
delay(5);
digitalWrite(digit[i],LOW);
number=number/10;
if(millis()-time>=1000)
{
time=millis();
if(numKeys%3==0)
{
count++;
if(count>9999)
count=0;
}
}
}
}
沒有留言:
張貼留言