int val1;
int val2;
int num;
int cnt=0;
int btnkey=0;
int j;
int seg7[]={2,3,4,5,6,7,8,9};
int sw1=14;
int sw2=15;
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(sw1,INPUT);
digitalWrite(sw1,HIGH);
pinMode(sw2,INPUT);
digitalWrite(sw2,HIGH);
for(int i=0;i<8;i++)
{
pinMode(seg7[i],OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
val1=digitalRead(sw1);
if(val1==LOW)
{
delay(20);
while(digitalRead(sw1)==LOW);
btnkey++;
cnt++;
if(cnt>9)
cnt=0;
}
val2=digitalRead(sw2);
if(val2==LOW)
{
delay(20);
while(digitalRead(sw2)==LOW);
btnkey++;
cnt--;
if(cnt<0)
cnt=9;
}
num=cnt;
for(j=0;j<8;j++)
{
if(bitRead(seg7Table[num%10],j))
digitalWrite(seg7[j],LOW);
else
digitalWrite(seg7[j],HIGH);
}
}
沒有留言:
張貼留言