wiring bumper switches / code syntax

How do I wire two bumper switches into the Arduino? How may the wiring of the switches change the code’s syntax? I’m using an Arduino Mega with Adafruit’s Motor Shield. Please use my code as example. Thanks.

#include <AFMotor.h>

AF_DCMotor motor1(1,MOTOR12_64KHZ);
AF_DCMotor motor2(2,MOTOR12_64KHZ);

int sleft = 52; //left bumper switch
int sright = 53; //right bumper switch
int lval; //left switch state
int rval; //right switch state

void setup()
{
  Serial.begin(9600);
  Serial.println("Here we go!");
  
  pinMode(sleft,INPUT);
  pinMode(sright,INPUT);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
  digitalWrite(sleft,LOW);
  digitalWrite(sright,LOW);
}

void loop()
{
  lval = digitalRead(sleft);
  rval = digitalRead(sright);
  while (lval == LOW,rval == LOW)
  { 
   motor1.run(FORWARD);
   motor2.run(FORWARD);
  }
  if (lval == LOW,rval == HIGH)
  {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    delay(1500);
    motor1.run(BACKWARD);
    motor2.run(FORWARD);
    delay(750);
  }
  if (lval == HIGH,rval == LOW)
  {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    delay(1500);
    motor2.run(BACKWARD);
    motor1.run(FORWARD);
    delay(750);
  }
  if (lval == HIGH,rval == HIGH)
  {
    Serial.print("WTF!!!");
    delay(3000);
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    delay(1500);
    motor1.run(BACKWARD);
    motor2.run(FORWARD);
    delay(2250);
  }
}

It depends a little on whether your switches are normally-open or normally-closed, but I'd make use of the internal pull-ups.

pinMode(sleft,INPUT);
  pinMode(sleft,INPUT);
  digitalWrite(sleft,HIGH);

Wire the switch between the input pin and ground. If the switch is normally-open, it will read LOW on a bump, and the opposite if it normally-closed

:)Thanks for your response.

I tried to wire the switches like the one in this picture, but they didn't work. We removed the wire from the ground pin and just used the 5V pin and the input pin with a 10 Kohm resistor, which seemed to work. Any idea why?

http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg

Also, the syntax difference I'm referring to is where to put the digitalWrite (in void setup or void loop) and if this has to do with the switch wiring.

Not sure which ground wire you're referring to. I'm not sure I'd power that motor off your Arduino either.

The digitalWrite to set the internal pull-ups would normally go in setup.

The resistor in the image goes to the negative line in the breadboard, which is connected to the ground pin in the arduino (follow the cables). I'm using the motor shield with an external power supply.