I want to activate the steppermotor depending on which key I press. I currently have two different ones which can be turned on. My goal is to hit "." to turn on 1 of them, and then "," to turn on the other. The LED turns on and the serial monitor prints the correct variable so the IF statements work at the end, however the motors do not turn on.
This is my code:
// MultiStepper.pde
// -- mode: C++ --
#include <AccelStepper.h>
//Stepper2 pins
#define STEPPER2_DIR_PIN 55
#define STEPPER2_STEP_PIN 54
#define STEPPER2_ENABLE_PIN 38
//Stepper3 pins
#define STEPPER3_DIR_PIN 61
#define STEPPER3_STEP_PIN 60
#define STEPPER3_ENABLE_PIN 56
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
AccelStepper stepper3(AccelStepper::DRIVER, STEPPER3_STEP_PIN, STEPPER3_DIR_PIN);
int runStepper;
void setup()
{
stepper2.setMaxSpeed(300); //multi
stepper2.setAcceleration(150.0);
stepper2.moveTo(-3000); //negative values go forward, maximum is about 205000 from start.
stepper3.setMaxSpeed(300);
stepper3.setAcceleration(150.0);
stepper3.moveTo(-3000); //negative values go forward, maximum is about 140000 from start.
stepper2.setEnablePin(STEPPER2_ENABLE_PIN);
stepper2.setPinsInverted(false, false, true);
stepper2.enableOutputs();
stepper3.setEnablePin(STEPPER3_ENABLE_PIN);
stepper3.setPinsInverted(false, false, true);
stepper3.enableOutputs();
Serial.begin(9600);
Serial.println(" Arduino Serial Servo Control");
Serial.println("Press < or > to move, spacebar to center");
Serial.println();
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if (Serial.available() > 0) {
runStepper = Serial.read();
if (runStepper == '.') {
stepper2.run();
digitalWrite(LED_BUILTIN, HIGH);
Serial.write("stepper2 should be on");
delay(2000);
}
if (runStepper == ',') {
stepper3.run();
digitalWrite(LED_BUILTIN, LOW);
Serial.write("stepper3 should be on");
delay(2000);
}
Serial.write(runStepper);
delay(100);
}
}