Arduino 通过串口字符串控制LED开关

时间:2025-03-07 17:08:43



String comdata="";
String out01on="out01on#";
String out01off="out01off#";
int led=13;
void setup() {
  // put your setup code here, to run once:
  (9600);
  ("Example 1!");
}

void loop() {
  // put your main code here, to run repeatedly:

  if (())
  {
      while(()>0)
      {
       comdata +=char(());
       delay(2); 
      }

  if (comdata=="out01on#")
  {
   ("ON");
   digitalWrite(led,HIGH); 
  }
  else if(comdata=="out01off#")
  {
   ("OFF");
   digitalWrite(led,LOW); 
  }
  else
  {
    
  }
  comdata="";
  }
}