Hello
I am new to arduino
i am working on XY slider with the help of stepper motors and arduino
i wrote a code which has fixed delay values which works
now i am trying to wrote the code with the help of serial monitor which ask me to enter the delay time but that is not working
Please help me as early as possible
as my project submission dates are closer
i am pasting the code as below
#define EN 8
//Direction pin
#define X_DIR 5
#define Y_DIR 6
//#define Z_DIR 7
//Step pin
#define X_STP 2
#define Y_STP 3
//#define Z_STP 4
//A4988
int delayTime=900; //Delay between each pause (uS)
int stps=2000 ;// Steps to move
int a,b,c,d,e;
//int steps=5000;//steps to move in reverse direction
int someArray[5];
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup()
{
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
// pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
pinMode(EN, OUTPUT);
//digitalWrite(EN, LOW);
Serial.begin(9600) ;
Serial.println("Enter the number of iterations");
Serial.print(someArray[a]);
a=Serial.read();
Serial.println("Enter the Dipping time for first Precursor");
if(Serial.available()>=0)
{
Serial.print(someArray[b]);
Serial.println("Enter the Dipping time in distilled Water");
if(Serial.available()>=0)
{
Serial.print(someArray[c]);
Serial.println("Enter the Dipping time in second Precursor");
if(Serial.available()>=0)
{
Serial.print(someArray[d]);
Serial.println("Enter the Dipping time in distilled Water");
if(Serial.available()>=0)
{
Serial.print(someArray[e]);
}}}}
for(int i=1; i<=a; i++)
{
step(false, X_DIR, X_STP, stps); //X, Clockwise
if(Serial.available()>=0)
{
step(false, X_DIR, X_STP, stps); //X, Clockwise
b=Serial.read();
delay(b); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
step(false, X_DIR, X_STP, stps); //X, Clockwise
c=Serial.read();
delay(c); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
d=Serial.read();
delay(d); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
e=Serial.read();
delay(e); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
}
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise*/
delay(1000);
}
}
void loop()
{
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
stepper.ino (2.94 KB)