int i;
int KeyData;
int numKeys=0;
int val=0;
const int debounceDelay=20;
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 int seg[]={2,3,4,5,6,7,8,9}; //abcdefgp
const int sw=10;
void setup()
{
pinMode(sw,INPUT_PULLUP);
for(i=0;i<8;i++)
pinMode(seg[i],OUTPUT);
}
void loop()
{
KeyData=digitalRead(sw);
if(KeyData==LOW)
{
delay(debounceDelay);
while(digitalRead(sw)==LOW)
;
numKeys++;
}
if(numKeys%2==0)
{
val++;
if(val>9)
val=0;
}
else
{
val--;
if(val<0)
val=9;
}
for(i=0;i<8;i++)
{
if(bitRead(num[val],i))
digitalWrite(seg[i],HIGH);
else
digitalWrite(seg[i],LOW);
}
delay(1000);
}
沒有留言:
張貼留言