int btnkey;
int time;
int num;
int cnt=0;
int seg_7[]={2,3,4,5,6,7,8,9};//abcdefg
int com_sacn[]={10,11,12,13};//com3 com2 com1 com0
int sw=14;
int i;
int j;
int val;
int table_7seg[]=
{
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
//------------------------------------------------------
void setup() {
// put your setup code here, to run once:
pinMode(sw,INPUT);
digitalWrite(sw,HIGH);
for(int i=0;i<8;i++)
{
pinMode(seg_7[i],OUTPUT);
}
for(i=0;i<4;i++)
{
pinMode(com_sacn[i],OUTPUT);
digitalWrite(com_sacn[i],LOW);
}
}
//--------------------------------------------------------
void loop() {
// put your main code here, to run repeatedly:
val=digitalRead(sw);
if(val==LOW)
{
delay(20);
while(digitalRead(sw)==LOW);
btnkey++;
}
num=cnt;
for(i=3;i>=0;i--)
{
for(j=0;j<8;j++)
{
if(bitRead(table_7seg[num%10],j))
digitalWrite(seg_7[j],LOW);
else
digitalWrite(seg_7[j],HIGH);
}
digitalWrite(com_sacn[i],HIGH);delay(5);
digitalWrite(com_sacn[i],LOW);
num=num/10;
if(millis()-time>1000)
{
time=millis();
if(btnkey % 2==0)
{
cnt++;
if(cnt>9999)
cnt=0;
}
else
{
cnt--;
if(cnt<0)
cnt=9999;
}
}
}
}
沒有留言:
張貼留言