const int motor11=30;//LEFT MOTOR FW
const int motor12=31;//LEFT MOTOR BK
const int motor1pwm=2;
const int motor21=40;//RIGHT MOTOR FW
const int motor22=41;//RIGHT MOTOR BK
const int motor2pwm=8;
If you used meaningful names, like leftFW, leftBK, leftSpeed, rightFW, rightBK, and rightSpeed, you would not need comments AND you couldn't possible activate the wrong pin accidentally.
int flag1=0, flag2=0, flag3=0, flag4=1, flag5=0;//flag1 is for set point, flag2 is for slow start, flag3, flag4 for changing x, flag5 for changing y
Better names would eliminate the need for useless comments AND the need to scroll back to figure out WTF the code is supposed to be doing.
timer = millis();
The millis() function returns a time, NOT a timer.
if(y==5)
{
while(true)
{
digitalWrite(motor11, LOW);
digitalWrite(motor12, LOW);
analogWrite(motor1pwm, 120);
digitalWrite(motor21, LOW);
digitalWrite(motor22, LOW);
analogWrite(motor2pwm, 30);
}
}
If y ever does equal 5, you've got an infinite loop here to assure that the robot never does anything more than the hokey-pokey for the rest of time.
Your code is in serious need of more Serial.print() statements, so you KNOW what it is doing.