int val;
int num;
int cnt=0;
int btnkey=0;
unsigned long time=0;
int j;
int seg7[]={2,3,4,5,6,7,8,9};
int sw=14;
int seg7Table[]=
{
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(seg7[i],OUTPUT);
}
}
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(j=0;j<8;j++)
{
if(bitRead(seg7Table[num%10],j))
digitalWrite(seg7[j],LOW);
else
digitalWrite(seg7[j],HIGH);
}
if(millis()-time>=1000)
{
time = millis();
if(btnkey % 2 ==0)
{
cnt++;
if(cnt>9)
cnt=0;
}
else
{
cnt--;
if(cnt<0)
cnt=9;
}
}
}
沒有留言:
張貼留言