Skip to main content
Arduino

Return to Answer

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

Gerben's comment Gerben's comment:

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}

Gerben's comment:

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}

Gerben's comment:

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}
Quote referenced comment in answer. This makes it more clear what the required change was and the reason for it.
Source Link

Gerben's comment as anGerben's comment :

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}

Gerben's comment as an answer is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}

Gerben's comment :

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}
Source Link
Dave X
  • 2.4k
  • 15
  • 29

Gerben's comment as an answer is:

#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.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /