我正在尝试让 Arduino Uno 板控制由伺服电机驱动的夹具。伺服器试图低于 134°,这在机械上是不可能的。我能做些什么来解决这个问题?
我试图将电机限制在 180°,当它不是所需按钮的读数时,它会保持主要位置(关闭,180)
#include <Servo.h>
Servo myservo;
char reading;
int pos;
void setup() {
// put your setup code here, to run once:
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
reading = Serial.read();
Serial.print(reading);
if (reading == 'W' || reading == 'w') {
pos = 134;
myservo.write(pos);
Serial.println("Open");
}
else if (reading == 'C' || reading == 'c') {
pos = 180;
myservo.write(pos);
Serial.println("Close");
}
else if (reading != 'W' || reading != 'C') {
myservo.write(180);
}
}
}