步进电机 接收指定步数测试程序

    xiaoxiao2021-04-17  44

    #include <Stepper.h> const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor // initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 3,2); String comdata = ""; //接收串口数据 int stepCount = 0; // number of steps the motor has taken void setup() { // initialize the serial port: Serial.begin(9600); myStepper.setSpeed(200); } void loop() { // step one step: //接收串口数据 while (Serial.available() > 0) { comdata += char(Serial.read()); delay(2); } //数据类型转换 if (comdata.length() > 0) { stepCount = comdata.toInt(); Serial.println(stepCount); comdata = ""; } if(stepCount>0){ myStepper.step(stepCount); stepCount = 0; } }
    转载请注明原文地址: https://ju.6miu.com/read-674080.html

    最新回复(0)