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()
{
// put your setup code here, to run once:
int a;
for(a=0;a<8;a++)
{
pinMode(led_pin[a],OUTPUT);
}
}
//--------------------------------
void outport(unsigned 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()
{
for(i=0;i<8;i++)
{
outport(led_table[i]);
delay(1000);
}
}
沒有留言:
張貼留言