Stuck the stepper.run in the main code, it is responding to the serial monitor and doing what I want now. However, every time the code is loaded onto the Arduino, both steppers do a half turn in the same direction?
#include <AccelStepper.h>
AccelStepper stepper1(AccelStepper::FULL4WIRE, 5, 6, 7, 8);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 9, 10, 11, 12);
int movement = 360;
void setup()
{
Serial.begin(9600);
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(movement);
stepper2.setMaxSpeed(200.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(movement);
}
char inBuffer = "";
void loop()
{
if(Serial.available()>0)
{
inBuffer = Serial.read();
}
if (inBuffer == 'a')
{
Serial.println("test point 1");
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
}
if (inBuffer == 'b')
{
Serial.println("test point 2");
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
}
stepper1.run();
stepper2.run();
inBuffer = "";
}
How would you recommend getting around this issue?
Robin2:
The Arduino is a great system for learning-by-doing.
Incredible!