int btn1=9;
int btn2=10;
int seg7_pin[]={2,3,4,5,6,7,8};
char seg7_table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};
int i;
int j;
int k;
int num;
int val1;
int val2;
void setup()
{
pinMode(btn1,INPUT);//pinMode(btn,OUTPUT)complier無法知道error
pinMode(btn2,INPUT);
for(i=0;i<7;i++)
{
pinMode(seg7_pin[i],OUTPUT);
}
}
//--------------------------------------
void outport(char data)
{
for(k=0;k<7;k++)
{
if(data % 2 ==1)
digitalWrite(seg7_pin[k],HIGH);
else
digitalWrite(seg7_pin[k],LOW);
data=data/2;
}
}
//---------------------------------------
void loop()
{
val1=digitalRead(btn1);
val2=digitalRead(btn2);
if(val1==LOW)
{
delay(1000);
while(digitalRead(btn1)==LOW);
if(num==9)//試出來的,num==10會多一個,所以變9就可以了
num=0;
else
num++;
}
if(val2==LOW)
{
delay(1000);
while(digitalRead(btn2)==LOW);
if(num==0)
num=9;
else
num--;
}
outport(seg7_table[num]);
}
沒有留言:
張貼留言