Robot Code Not Working

So I’ve been working on my first automated robot for about a month now and I can never seem to get it to work proprly here is my current code (I Know it’s not pretty.)

int vcc = 2; 
int trig = 3; 
int echo = 4; 
int gnd = 5; 
#define Motor1 11
#define MotorPower1 10
#define Motor2 6
#define MotorPower2 9



void setup() {

  Serial.begin (9600);
pinMode (vcc,OUTPUT);
pinMode (gnd,OUTPUT);
  pinMode(Motor1, OUTPUT);
  pinMode(Motor2, OUTPUT);
  pinMode(MotorPower1, OUTPUT);
  pinMode(MotorPower2, OUTPUT);
  pinMode(8, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(7, OUTPUT);
  pinMode(13, OUTPUT);

}


void loop() 
{
digitalWrite(vcc, HIGH);

long duration, distance;
int sensorVal = digitalRead(12);
int sensorValB = digitalRead(8);

pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);


pinMode(echo,INPUT);
duration = pulseIn(echo, HIGH);
distance = (duration/2) / 29.1;


  if (distance < 28 ) { 

 analogWrite (MotorPower1, 0);
 analogWrite (MotorPower2, 255);
 analogWrite (Motor1, 255);
 analogWrite (Motor2, 0);

}
  else {

if (sensorValB = LOW) {
 analogWrite(MotorPower1, 255);
 analogWrite(MotorPower2, 255);
 analogWrite( Motor1, 0);
 analogWrite( Motor2, 0);
}
else {
if (sensorVal = LOW) {
 analogWrite(MotorPower1, 255);
 analogWrite(MotorPower2, 255);
 analogWrite( Motor1, 0);
 analogWrite( Motor2, 0);
}
 else {
 analogWrite(MotorPower1, 0);
 analogWrite(MotorPower2, 0);
 analogWrite( Motor1, 255);
 analogWrite( Motor2, 255);

}
} 
}

delay (10);
Serial.println (sensorValB);
Serial.println (sensorVal);

  }

Basicly I have a ultrasonic sensor which works fine (if it detects something within 28 cm it turns till there’s nothing in front) but I also have 2 little switched which are meant to make it reverse if they hit into something (they are anti tamper switches from a pc so they are super sensitive) but every time I add them into the code above it stops being able to read if they are pressed but the base code for the switches works fine. finally I am using 2 dc motors (just standard one you would find in a kids rc car or something) and whenever i add a delay of about a second or more they glitch out and start stop start stop quickly is there a way I could have it go backward for say 5 seconds then turn when the switch is hit without the delay that would be needed to make that happen glitching the wheels out other then changing what type of motor it is.

I Know it's not pretty.

Nor is it in [­code]...[­/code] tags

Please read this before posting a programming question and follow the advice. Unless, of course, your code really does have a smiley in it.

Please use code bar !

int vcc = 2; 
int trig = 3; 
int echo = 4; 
int gnd = 5;

This is connection for your ultra sonic sensor?

Check this out.

https://www.arduino.cc/en/Tutorial/Button

I think your problem is because you use this https://www.arduino.cc/en/Reference/Assignment but should use thishttps://www.arduino.cc/en/Reference/If

int sensorValB = digitalRead(8);

Reading from the smiley face pin is notoriously inaccurate. Perhaps you should try a different pin.

Perhaps you should NOT try to use the data until you know that the data is any good.

so basicly I just need to put == insted of =. any ideas on how to get past the problem with the delay?

any ideas on how to get past the problem with the delay?

Sure. Don't use delay(). The blink without delay example shows how to make things happen a fixed time later without using delay().