I’m using an adafruit motor shield (v1) to control two stepper motors, with a bluetooth remote control, for a wheeled robot project. I can make the motors go forward, back, etc.
But how do I stop them when they are moving?
I tried adding an If statement for detecting a bluetooth signal in the middle of the stepper loop (see code below), but that stops the stepper after just one step. Thanks for the help. If anyone has any other suggestions for alternative robot libraries for driving stepper motors other than just the stock adafruit motor library, please let me know.
[code]
#include <AFMotor.h>
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);
char cmdCode = '0';
int cmdValue = 0;
#define serial Serial
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
motor1.setSpeed(30); // 30 rpm
motor2.setSpeed(30); // 30 rpm
}
void processEvents() {
}
void loop()
{
processEvents();
//Receives commands from android device:
{
int inByte = serial.read();
serial.println((char)inByte);
switch ((char)inByte)
{
case 'f': //Moves Both Motors Forward
for (int i = 0; i < 1000; i++)
int inByte = serial.read();
if (inByte == 's') switch ((char)inByte);case
{
motor1.step(1, FORWARD, DOUBLE);
motor2.step(1, FORWARD, DOUBLE);
}
break;
case 's':
motor1.release();
motor2.release();
break;
}
}
}
[/code]