int led_pin[]={2,3,4,5,6,7,8,9};
int led_table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
int btn1=10;
int num=-1;
int direct=0;
int val;
void setup()
{
int x;
pinMode(btn1,INPUT);
for(x=0;x<8;x++)
{
pinMode(led_pin[x],OUTPUT);
}
}
void outport(unsigned char data)
{
int x;
for(int 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()
{
if(num==7)//小括號要寫兩個等於等於,否則只會停在第1個LED
num=0;
else
num++;
outport(led_table[num]);
delay(1000);
}
沒有留言:
張貼留言