stepper and laser read photo sensor project

#include <AccelStepper.h>
#include <AFMotor.h>
#include <Stepper.h>

AF_Stepper motor1(200, 1);// not using this any more
AF_Stepper motor2(200, 2);// <--- this ch is hooked to the stepper moveing my X axis to each notch of the part





const int  D1 = A7;//< photo sensor pin call out for laser detection
int sensorValue = A7;// think i need this to map the value to a high low reading for the photo sensor
int lastValue = A7;

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");
  pinMode(49, OUTPUT); // pin with realy for air valve
  pinMode(48, OUTPUT); //toggle...laser... save dieode life
  //spacer for laser below
  motor1.setSpeed(178);
  motor1.step(8, FORWARD, DOUBLE);
  motor1.step(4, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();

  // spaser for laser above
  delay(300);
  int sensorValue = analogRead(A7);


  lastValue = map(sensorValue, 0, 600, 0, 600);
  Serial.println(sensorValue);
  sensorValue = analogRead(A7);

  

  sensorValue = analogRead(A7);
  while (sensorValue > 500){
    motor1.setSpeed(170);
    motor1.step(1, FORWARD, DOUBLE);
    motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
    motor1.release();
    sensorValue = analogRead(A7);
  }

  Serial.println(sensorValue);
  delay(100);

  //spacer for laser below
  motor1.setSpeed(178);
  motor1.step(100, FORWARD, DOUBLE);
  motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();

  digitalWrite(49, HIGH);   // set the LED on to toggle realy to air valve
  delay(800);              // wait for a second for air to reach max psi in sander and piston
  digitalWrite(49, LOW);    // set the LED off relase air valve
  delay(1000);      //wait one second for air to exit piston and return sander to home postion

  // using a comand to the stepper as follows will allow the next laser calbration to not have a false reading from the .400 thick high

  // if it dose not advance forward past the high notch the laser with be geting the same reading from the last time it was checked
  motor1.setSpeed(220);
  motor1.step(1000, FORWARD, DOUBLE);
  motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();




  sensorValue = analogRead(A7);
  while (sensorValue > 500){
    motor1.setSpeed(170);
    motor1.step(1, FORWARD, DOUBLE);
    motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
    motor1.release();
    sensorValue = analogRead(A7);
  }

  Serial.println(sensorValue);
  delay(100);

  //spacer for laser below
  motor1.setSpeed(178);
  motor1.step(100, FORWARD, DOUBLE);
  motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();

  digitalWrite(49, HIGH);   // set the LED on to toggle realy to air valve
  delay(800);              // wait for a second for air to reach max psi in sander and piston
  digitalWrite(49, LOW);    // set the LED off relase air valve
  delay(1000);      //wait one second for air to exit piston and return sander to home postion

  // using a comand to the stepper as follows will allow the next laser calbration to not have a false reading from the .400 thick high

  // if it dose not advance forward past the high notch the laser with be geting the same reading from the last time it was checked
  motor1.setSpeed(220);
  motor1.step(1000, FORWARD, DOUBLE);
  motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();


  sensorValue = analogRead(A7);
  while (sensorValue > 500){
    motor1.setSpeed(170);
    motor1.step(1, FORWARD, DOUBLE);
    motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
    motor1.release();
    sensorValue = analogRead(A7);
  }

  Serial.println(sensorValue);
  delay(170);

  //spacer for laser below
  motor1.setSpeed(178);
  motor1.step(100, FORWARD, DOUBLE);
  motor1.step(0, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();

  digitalWrite(49, HIGH);   // set the LED on to toggle realy to air valve
  delay(800);              // wait for a second for air to reach max psi in sander and piston
  digitalWrite(49, LOW);    // set the LED off relase air valve
  delay(1000);      //wait one second for air to exit piston and return sander to home postion

  // using a comand to the stepper as follows will allow the next laser calbration to not have a false reading from the .400 thick high

  // if it dose not advance forward past the high notch the laser with be geting the same reading from the last time it was checked
  motor1.setSpeed(220);
  motor1.step(0, FORWARD, DOUBLE);
  motor1.step(10050, BACKWARD, DOUBLE);//   1500 steps is aproxmitly 0.375 inchs  .025 short of next notch
  motor1.release();


}

void loop() {
  // no loop for this in till i figue out how to drop all this in to one large if statement for a push button switch: 
delay(1000);
}