int i;
int num;
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);
Serial.println("press 0~7 toggle LED status");
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)
{
num = Serial.read();
num=int(num-'0');
if(num>=0 && num<=7)
{
status[num]=!status[num];
digitalWrite(led[num],status[num]);
Serial.print("LED status : ");
for(i=0;i<8;i++)
{
if(status[i]==1)
Serial.print("1");
else
Serial.print("0");
}
Serial.println();
}
}
}
沒有留言:
張貼留言