Motor Glitch

Hello me, a fellow student, and a teacher are making a robot, but one of our wheels keep glitching out whenever add delays to the code. we've also been trying to use a switch but it wont read it when we press the switch.

Thank you to anyone who answers this...

Heres the code...

int BUTTON2 = 0;
const int BUTTON=2;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;void setup() {

//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);

pinMode(2, INPUT);
}

boolean debounce (boolean last)
{
boolean current = digitalRead(BUTTON);
if (last != current)
{
delay(5);
current = digitalRead(BUTTON);
}
return current;
}

void loop(){

currentButton = debounce (lastButton);
if (lastButton == LOW && currentButton == HIGH)

//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
delay(200);

digitalWrite(13, HIGH);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);

if (BUTTON2 = HIGH){
digitalWrite(12, LOW);
digitalWrite(9, LOW);
analogWrite(11, 255);
delay(200);

digitalWrite(13, LOW);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);

}

else (BUTTON2 = LOW); {
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
analogWrite(11, 255);
delay(200);

digitalWrite(13, HIGH);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);
}

}

A number of problems are immediately apparent

 if (BUTTON2 = HIGH)

Firstly, = is used for assignment of a value whilst == is used for comparison
However, BUTTON2 is initialised to zero and is only ever changed to LOW, ie zero, so it will never equal HIGH

The delay()s will also cause problems because they literally stop the code for the delay() period so can slow down response to inputs considerably. I am sure that you will need to use non blocking timing at some time so I suggest that you look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.