int num;
int value;
int direct=0;
int btn1=10;
int led_pin[]={2,3,4,5,6,7,8,9};
int led_table[]={0x81,0x42,0x24,0x18,0x24,0x42};
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==5)
num=0;
else
num++;
}
else
{
if(num==0)
num=5;
else
num--;
}
outport(led_table[num]);
delay(1000);
}
沒有留言:
張貼留言