int btn1=10;
int direct=0;
int value;
int num;
int led_pin[]={2,3,4,5,6,7,8,9};
char led_table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int i;
void setup()
{
int a;
pinMode(btn1,INPUT);
for(a=0;a<8;a++)
{
pinMode(led_pin[a],OUTPUT);
}
}
//--------------------------------
void outport(byte 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(500);
}
沒有留言:
張貼留言