Arduino "An Error Occured While Uploading The Sketch" 试图用两个按钮控制步进电机

Arduino "An Error Occured While Uploading The Sketch" trying to control stepper motor with two buttons

#include <Servo.h>

int servoPin = 9;
int btnPin1 = 12;
int btnPin2 = 6;
int btnRead1;
int btnRead2;
int dt = 250;
int angle1 = 100;
int angle2 = 0;
Servo myServo;

void setup() {
  // put your setup code here, to run once:
  myServo.attach(servoPin);
  Serial.begin(9600);
  pinMode(servoPin, OUTPUT);
  pinMode(btnPin1, INPUT);
  pinMode(btnPin2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  btnRead1=digitalRead(btnPin1);
  btnRead2=digitalRead(btnPin2);
  Serial.println(btnRead1);
  Serial.print(" , ");
  Serial.print(btnRead2);
  if (btnRead1 == 1) {
    myServo.write(angle2);
  } else if (btnRead2 == 1) {
    myServo.write(angle2);
  } else {
    myServo.write(angle1);  
  }
  delay(dt);
}

每当我单击“复制错误消息”时,它只会显示“上传草图时发生错误”。

如有任何帮助,我们将不胜感激。

确保选择了正确的板。 确保选择了正确的 com 端口。 确保 arduino 连接正确。 也许更新图书馆。 尝试将其上传到另一个板。