const byte LED = 13;
char val;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED, OUTPUT);
Serial.println("Welcome to Arduino");
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()) { //查看序列埠是否有指令
val = Serial.read(); //將讀取到的指令,付與給val
if (val == '1') { //如果val的值為1
digitalWrite(LED, HIGH); //開啟LED
Serial.println("LED ON"); //序列埠列印出LED ON
} else if (val == '0') { //否則如果val的值為0
digitalWrite(LED, LOW); //關閉LED
Serial.println("LED OFF"); //序列埠列印出LED OFF
}
}
}