目前我正在编写一个代码,该代码应该将某个位置发送到某个位置并返回。高原正由步进机移动。我的目标是按下键盘上的“4”,然后步进器移动到某个位置。但是,我没有成功。我正在使用AccelStepper,目前我有以下代码:
#include <AccelStepper.h>
AccelStepper stepper(1, 5, 4);
int spd = 1000; // The current speed in steps/second
int sign = 1; // Either 1, 0 or -1
int buttonState = 0;
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(1000);
stepper.setSpeed(1000);
}
void loop()
{
char c;
if (Serial.available()) {
c = Serial.read();
if (c == 'f') { // forward
sign = 1;
}
if (c == 'r') { // reverse
sign = -1;
}
if (c == 's') { // stop
sign = 0;
}
if (c == '1') { // super slow
spd = 100;
}
if (c == '2') { // medium
spd = 900;
}
if (c == '3') { // fast
spd = 1000;
}
if (c == '4') {
//not working, does anyone know how to do this?
stepper.moveTo(500);
}
stepper.setSpeed(sign * spd);
}
stepper.runSpeed();
}
有没有人有提示或知道如何实现这一目标?
谢谢你提前!