后续参考
import serial
import sys
def deleycontrol(i):
i = input().strip()
serialcomm.write(i.encode())
serialcomm.close()
if __name__ == '__main__':
serialcomm = serial.Serial('COM9', 9600)
serialcomm.timeout = 1
deleycontrol(sys.argv[0])
String code;
void setup(){
Serial.begin(9600);
pinMode(7,OUTPUT);
}
void loop(){
if (Serial.available()>0){
code = Serial.readStringUntil('\n');
if (code=="0"){
digitalWrite(7,HIGH);
}
if (code=="1"){
digitalWrite(7,LOW);
}
}
}