int num;
int value;
int direct=0;
int btn1=10;
int led_pin[]={2,3,4,5,6,7,8,9};
int led_table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int i,j;
void setup()
{
int a,b;
pinMode(btn1,INPUT);
for(a=0;a<8;a++)
{
pinMode(led_pin[a],OUTPUT);
}
}
void outport(unsigned char data)
{
int x;
for(x=0;x<8;x++)
{
if(data %2 ==1)
digitalWrite(led_pin[x],HIGH);
else
digitalWrite(led_pin[x],LOW);
data=data/2;
}
}
void loop()
{
value=digitalRead(btn1);
if(value==LOW)
{
delay(1000);
while(digitalRead(btn1)==LOW);
direct=direct^1;
}
if(direct==0)
{
if(num==7)
num=0;
else
num++;
}
else
{
if(num==0)
num=7;
else
num--;
}
outport(led_table[num]);
delay(1000);
}
沒有留言:
張貼留言