int sw=10;
int pin7seg[]={2,3,4,5,6,7,8,9};
int val;
int cnt;
int num=-1;
int j;
int table7seg[]=
{
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_PULLUP);
for(int i=0;i<8;i++)
{
pinMode(pin7seg[i],OUTPUT);
}
}
void loop()
{
// put your main code here, to run repeatedly:
val=digitalRead(sw);
if(val==LOW)
{
delay(20);
while(digitalRead(sw)==LOW);
cnt++;
}
if(cnt % 2==0)
{
num++;
if(num>9) num=0;
}
else
{
num--;
if(num<0)
num=9;
}
for(j=0;j<8;j++)
{
if(bitRead(table7seg[num],j))
digitalWrite(pin7seg[j],LOW);
else
digitalWrite(pin7seg[j],HIGH);
}
delay(1000);
}
沒有留言:
張貼留言