Hi there, I am looking to control my stepper motor's speed with arduino's serial monitor, I am using UNO and Adafruit Motor Shield V2.3
There are 4 speed divided into 4 categories a, b, c and d, the idea is that when you press 'a' the stepper motor would rotate on the selected RPM, 'b' another RPM and so-on. Press 's' and motor would stop
Everything is fine when i press 'a'. However when I want to change to 'b' there isnt any response from the motor and it will continue rotating in 'a' setting.
Attached is my code for the above scenario. Please advice
Thank you
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup() {
Serial.begin(9600);
Serial.println("Stepper Test");
AFMS.begin();
//AFMS.begin(1000);
}
void loop() {
char n;
if (Serial.available() > 0)
{
int command = Serial.read();
{
if (command == 'a')
{
Serial.println("Setting Speed to 19.1 RPM");
delay (1000);
do
{
myMotor->setSpeed(19.1);
myMotor->step(10000,FORWARD, DOUBLE);
} while (Serial.available() == 0);
Serial.read();
}
else if (command == 'b')
{
Serial.println("Setting Speed to 38.2 RPM");
delay (1000);
myMotor->setSpeed(38.2);
myMotor->step(10000,FORWARD, DOUBLE);
}
else if (command == 'c')
{
Serial.println("Setting Speed to 57.3 RPM");
delay (1000);
myMotor->setSpeed(57.3);
myMotor->step(10000,FORWARD, DOUBLE);
}
else if (command == 'd')
{
Serial.println("Setting Speed to 76.4 RPM");
delay (1000);
myMotor->setSpeed(76.4);
myMotor->step(10000,FORWARD, DOUBLE);
}
else if (command == 's')
{
myMotor->release();
;
}
}
}
}