|
6#
樓主 |
發表於 2016-5-12 10:54:34
|
只看該作者
前輩以下是我的程式 可是顯示出來的燈號有問題...輸入A因該要滅亮滅滅 滅滅滅亮
可是我的顯示滅亮滅亮滅亮滅亮!
int i;
int led[]={2,3,4,5,6,7,8,9};
int status[]={0,0,0,0,0,0,0,0};
void setup()
{
Serial.begin(9600);
for(i=0;i<8;i++)
pinMode(led[i],OUTPUT);
for(i=0;i<8;i++)
digitalWrite(led[i],LOW);
}
void loop()
{
if(Serial.available()>0)
{
byte data = Serial.read();
if(data&1)
digitalWrite(2,HIGH);
else
digitalWrite(2,LOW);
if(data&2)
digitalWrite(3,HIGH);
else
digitalWrite(3,LOW);
if(data&3)
digitalWrite(4,HIGH);
else
digitalWrite(4,LOW);
if(data&4)
digitalWrite(5,HIGH);
else
digitalWrite(5,LOW);
if(data&5)
digitalWrite(6,HIGH);
else
digitalWrite(6,LOW);
if(data&6)
digitalWrite(7,HIGH);
else
digitalWrite(7,LOW);
if(data&7)
digitalWrite(8,HIGH);
else
digitalWrite(8,LOW);
if(data&0x80)
digitalWrite(9,HIGH);
else
digitalWrite(9,LOW);
}
} |
|