First post, but have read countless forum topics for my Arduino projects and appreciate all contributors...amazing people.
My project is trying to have a stepper motor reach a certain angle in the y-axis if a certain benchmark in the x-axis is reached. I have tried for, if, whiles, do...whiles, and they all do something different. Some just loop inside the loop, or two if's just cycle once through. Below is my latest effort and figure I can start from here:
#include <Stepper.h>
const int stepsPerRevolution = 2050; // designating # of steps per revolution
Stepper myStepper(stepsPerRevolution, 5,4,6,8); // pin designation for Stepper Motor
int stepCount = 0; // number of steps the motor has taken
const int ypin = A2; // y-axis
const int xpin = A1; // x-axis
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
}
void loop(){
// read the sensor value:
int xsensorReading = analogRead(A1);
int ysensorReading = analogRead(A2);
int angle = map(ysensorReading, 315, 345, 30, 0);
if (xsensorReading > 333) //Setting the benchmark in x-axis
{
if (angle > 13) // I would like this "if" statement to loop until the stepper reaches 13 I have used "while" and it freezes up
{ // Several of the above control structures discussed haven't worked nor does this one
myStepper.setSpeed(13);
myStepper.step(-stepsPerRevolution/50);
}
if (angle < 13)
{
myStepper.setSpeed(13);
myStepper.step(stepsPerRevolution/50);}
}
else (xsensorReading < 333);
{
myStepper.setSpeed(0);
}
// print the sensor values:
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print(angle);
Serial.print("\t");
Serial.print(analogRead(xpin));
Serial.println();
// delay before next reading:
delay(10 );}
-----So while the y-axis is rotating, I would like it to be completed before seeing the x-axis again. Is there a better control structure? I have replaced those subsequent if's with while's, but it freezes up. Are two "while" loops to much?
Thanks for any insight!