Arduino servo

Stepper motor control can only turn the number of degrees, I do not know what to

Motor is energized to turn, can not control the angle of rotation

Steering gear to control the number of degrees turn, can now know in which angle

#include <Servo.h>
Servo servo1;
String comdata = "";
void setup() { //将步进电机用到的IO管脚设置成输出
  Serial.begin(9600);
  servo1.attach(5);
  servo1.write(0);
}
void loop() {
  while (Serial.available() > 0)
  {
    comdata += char(Serial.read());
    delay(2);
  }
 if (comdata.length() > 0)
  {
   if (comdata == "0") 
   {
      
    } 
    else if (comdata == "1") {
      
    }
   else if(comdata == "2")
   {
     
    }
  servo1.write(comdata.toInt());
  delay(5);
    comdata = "";
  }
}

 

Guess you like

Origin blog.csdn.net/qq_39097425/article/details/91873378