This seems crazy
for (y = 1; y < 10 ; y++) //y<24
//amount of ticks
{
digitalWrite(stp, HIGH); //Trigger one step
delay(150);
digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again
delay(150);
if (Serial1.available())//check whether the serial port has data input
{
if(Serial1.read()==HEADER)// determine data package frame header 0x59
{
uart[0]=HEADER;
if(Serial1.read()==HEADER)//determine data package frame header 0x59
{
uart[1]=HEADER;
for(i=2;i<9;i++)// store data to array
{
uart[i]=Serial1.read();
}
check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
if(uart[8]==(check&0xff))// check the received data as per protocols
{
dist=uart[2]+uart[3]*256;// calculate distance value
Serial.print("dist = ");
Serial.print(dist);// output LiDAR tests distance value
Serial.print('\t');
Serial.print('\n');
}
}
}
} //end of Lidar code
}
Why are you mixing up stepper code and LIDAR code. Put the stepper code into one function and the LIDAR code into another function. Then you can test each of the separately.
If you want a responsive program don't use delay() anywhere. Use millis() to manage timing as illustrated in Several Things at a Time.
Have a look at Using millis() for timing. A beginners guide if you need more explanation.
Also have a look at the second example program in this Simple Stepper Code
...R
Stepper Motor Basics
Planning and Implementing a Program