int led =13;
char ch;
void setup()
{
// put your setup code here, to run once:
pinMode(led,OUTPUT);
Serial.begin(9600);
Serial.println("+/- to turn on/off the LED");
}
void loop()
{
// put your main code here, to run repeatedly:
if(Serial.available())
{
ch =Serial.read();
}
if (ch=='+')
{
delay(1000);//delay 1秒中才不會一直出現ON字
Serial.println("ON");
digitalWrite(led,HIGH);
}
else if(ch=='-')
{
delay(1000);//delay 1秒中才不會一直出現OFF字
Serial.println("Off");
digitalWrite(led,LOW);
}
}
沒有留言:
張貼留言