int led_pin[]={2,3,4,5,6,7,8,9};
char led_table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
int i=-1;
int j;
void setup()
{
int a;
pinMode(13,OUTPUT);
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 foever()
{
digitalWrite(13,HIGH);delay(100);
digitalWrite(13,LOW);delay(100);
}
void loop()
{
foever();
if(i==7)
i=0;
else
i++;//-1+1=0 1 2 3 4 5 6 7
outport(led_table[i]);
delay(1000);
}
沒有留言:
張貼留言