two sensor and one stepper motor

am reading two sensor and make my stepper motor to move to the one with highest intensity, but it does go so slow and even when I shine on the other, still the motor spin slow
here is my code

#include<AccelStepper.h>
AccelStepper motor1(1,8,9);


//variable initialization
int esV,wsV; //east sensor value esV AND west sensor value wsV
int dwe; //difference west and east value
int pos=4000; //movement of tilt step

#define sensor0 0 //west sensor
#define sensor1 1 //east sensor

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  motor1.setMaxSpeed(10000);
  motor1.setAcceleration(10);

}

void loop() {
  //read sensor then map west and east to get new values wsV AND esV
  //difference of wsV and esV call the function dweV 
  sensorV();
  dweV();   
  tilt();

  //  Serial.print("westvalues: ");
  Serial.print(wsV);
  Serial.print(" ");
  //  Serial.print("east values: ");
  Serial.println(esV);
  //  Serial.print(" difference west east  ");
  //  Serial.println(dwe);

}//end of void loop

void sensorV()
{
  wsV=analogRead(sensor0);
  wsV=map(wsV,0,1023,0,255);
  wsV=constrain(wsV,0,255);

  esV=analogRead(sensor1);  
  esV=map(esV,0,1023,0,255);   
  esV=constrain(esV,0,255);
  delay(1000);
}//End of sensor reading

//this loop find the difference of sensor west and east
int dweV()
{
  //change of west and east values let call it cwe

  dwe= wsV-esV;   
  return dwe;

}//end of difference west east


void tilt()
{
  if(dwe>0)
  {
    if(motor1.distanceToGo() ==0)
    motor1.moveTo(400);
    motor1.run();
  }
}

Are you using the names 'motor1' and 'motor2' or the names 'steeper1' and 'steeper2' for your steppers?

This looks wrong:

//we are using 8,9,10,11 where (8&10 steppin motor 1&2 and 9 11 dirpin motor 1&2)
AccelStepper motor2(1,10,11);
AccelStepper motor2(1,10,11);

This also looks wrong:

    steeper1.setMaxSpeed(500);
    steeper1.Acceleration(1000);

This is going to cause things to go slowly:

  delay(1000);

I agree Jojnwasser
I actually copy wrong file but same question. the actual code is follow

the tilt function just find the difference of the two sensors and the highest intensity is where the motor will tilt to. these are west and east sensor. I actually have four, but for now I want to experiment the tilt first.

my motor doesn’t move after I put this function of tilt. but I try separate to just move my motor to moveTo whatever position I was able to.

check my last function as well if there is any error in coding. I don’t get any error when I compile

#include<AccelStepper.h>
AccelStepper motor1(1,8,9);


//variable initialization
int esV,wsV; //east sensor value esV AND west sensor value wsV
int dwe; //difference west and east value
int pos=4000; //movement of tilt step

#define sensor0 0 //west sensor
#define sensor1 1 //east sensor

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  motor1.setMaxSpeed(10000);
  motor1.setAcceleration(10);

}

void loop() {
  //read sensor then map west and east to get new values wsV AND esV
  //difference of wsV and esV call the function dweV 
  sensorV();
  dweV();   
  tilt();

  //  Serial.print("westvalues: ");
  Serial.print(wsV);
  Serial.print(" ");
  //  Serial.print("east values: ");
  Serial.println(esV);
  //  Serial.print(" difference west east  ");
  //  Serial.println(dwe);

}//end of void loop

void sensorV()
{
  wsV=analogRead(sensor0);
  wsV=map(wsV,0,1023,0,255);
  wsV=constrain(wsV,0,255);

  esV=analogRead(sensor1);  
  esV=map(esV,0,1023,0,255);   
  esV=constrain(esV,0,255);
  delay(1000);
}//End of sensor reading

//this loop find the difference of sensor west and east
int dweV()
{
  //change of west and east values let call it cwe

  dwe= wsV-esV;   
  return dwe;

}//end of difference west east


void tilt()
{
  if(dwe>0)
  {
    if(motor1.distanceToGo() ==0)
    motor1.moveTo(400);
    motor1.run();
  }
}

thanks Johnwasser

I was able to make my motor move to specified distance. when I shine on one sensor it go to that distance and stop and when I shine on the other motor it goes on the other motor as specified distance and stop.

I am very pleased. my other question is the movement of the stepper is not so smooth even though I call run() I don’t know why? my new code now is

#include<AccelStepper.h>
AccelStepper motor1(1,8,9);


//variable initialization
int esV,wsV; //east sensor value esV AND west sensor value wsV
int dwe; //difference west and east value
int pos=4000; //movement of tilt step

#define sensor0 0 //west sensor
#define sensor1 1 //east sensor

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  motor1.setMaxSpeed(10000);
  motor1.setAcceleration(10);

}

void loop() {
  //read sensor then map west and east to get new values wsV AND esV
  //difference of wsV and esV call the function dweV 
  sensorV();
  dweV();   
  tilt();

  //  Serial.print("westvalues: ");
  Serial.print(wsV);
  Serial.print(" ");
  //  Serial.print("east values: ");
  Serial.println(esV);
  //  Serial.print(" difference west east  ");
  //  Serial.println(dwe);

}//end of void loop

void sensorV()
{
  wsV=analogRead(sensor0);
  wsV=map(wsV,0,1023,0,255);
  wsV=constrain(wsV,0,255);

  esV=analogRead(sensor1);  
  esV=map(esV,0,1023,0,255);   
  esV=constrain(esV,0,255);
  delayMicroseconds(100);
  
}//end of sensor reading

//this loop find the difference of sensor west and east
int dweV()
{
  //change of west and east values let call it cwe

  dwe= wsV-esV;   
  return dwe;

}//end of difference west east


//this loop will move only specified distance by checking the difference of the two sensor
void tilt()
{
  if(dwe>0)
  {
    if(motor1.distanceToGo() ==0)
      motor1.moveTo(400);
    motor1.run();
  }
  else
    if(motor1.distanceToGo() ==0)
    motor1.moveTo(-400);
    motor1.run();
  }

Your coding looks stupid. Why do you have the function dweV() , which calculates and returns a value ( and doesn't do anything else ) , and then in loop() you invoke the function dweV() but you don't get it's returned value ?

You need to develop some very basic understanding of how C/C++ functions work before asking silly questions.

is not stupid

I have four sensors. but now am working on just two of them. Commented serial print doesn't affect your program even a little bit. I chose not to displayed.

in fact, the code is fine. and now it does work fine. You should read what I just said that my program work fine except the motor steps is not so quite and smooth.

thanks for taking your time Michinyon with your nice comment about my code being stupid.

I don't know where you learn C/C++. be creative on your code. I am not smart than you but the line you say my code is not return values I don't know which line on my code tells you no values is return.

I was wanna take to school a little bit but anyway, you got the answer. by the way there is return on serialprint

everything seems to work

thanks so much everyone for the contribution

delays are never a good idea, use millis() instead
and i know the loop should go as fast as possible
in this loop the motor.run should be called as this dictates speed. every time this function is called it asks if a step may be made.
serial print is rather slow only 1000 characters a second. so keep it down amap.
this accelstepper is good however it needs a fast call another way is using a timer for that one.