int pinLed = 8;
void setup() {
// put your setup code here, to run once:
pinMode(pinLed,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0) {
char ch = Serial.read();
Serial.print(ch);
//开灯
if(ch == 'a') {
digitalWrite(pinLed,HIGH);
Serial.println("turn on");
}
//关灯
if(ch == 'b') {
digitalWrite(pinLed,LOW);
Serial.println("turn off");
}
}
}