Arduino PS2 Controller Problem with Arduino Motor Shield R3

I have problem when I try to control my dc motors with “Arduino Motor Shield R3” via “PS2 Controller” by using arduino mega 2560.

At my code, I say " when you click L1 and if the analog stick value of LY ( left y axis ) equals something on ps2, move forward according to the analog stick value of LY ". This part is working very well.

However, when I write code for the backward as writing like this :" when you click R1 and if the analog stick value of RY ( left x axis ) equals something on ps2, move forward according to the analog stick value of RY". Nothing appears. I tried to use other left and right stick values on x and y axis but dc motors are not working at all.

I am not able to figure out what is the problem really; so I am stuck at my project now. If someone would help me how to fix this problem I will be very happy, thank you very much.

Note:
I used the library provided by PlayStation 2 Controller Arduino Library v1.0 « The Mind of Bill Porter too.

This is my code loop part:

void loop(){

   
  if(error == 1) //skip loop if no controller found
  return; 
  
  if(type == 1 || type == 0){ //DualShock Controller
  ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate'spd


  // Motor 1 and 2 go forward 
  if( ps2x.Button(PSB_L1) && ps2x.Analog(PSS_LY) == 127){
    digitalWrite(9, HIGH); //Eengage the Brake for Channel A
    //md.setM1Speed(0);
    //md.setM2Speed(0);
    digitalWrite(8, HIGH); //Eengage the Brake for Channel B
      }else if( (ps2x.Button(PSB_L1) && ps2x.Analog(PSS_LY) >= 128) || (ps2x.Button(PSB_L1) && ps2x.Analog(PSS_LY) <= 126) ){
        digitalWrite(12, HIGH); //Establishes forward direction of Channel A
        digitalWrite(9, LOW);   //Disengage the Brake for Channel A
        analogWrite(3, ps2x.Analog(PSS_LY));   //Spins the motor on Channel A at full speed
        //md.setM1Speed(ps2x.Analog(PSS_LY));
        //md.setM2Speed(ps2x.Analog(PSS_LY)+30);
        digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, ps2x.Analog(PSS_LY));    //Spins the motor on Channel B at half speed
       }else if( ps2x.Button(PSB_GREEN) ) {
            digitalWrite(12, LOW); //Establishes backward direction of Channel A
            digitalWrite(9, LOW);   //Disengage the Brake for Channel A
            analogWrite(3, 165);   //Spins the motor on Channel A at half speed
            //md_1.setM1Speed(-ps2x.Analog(PSS_LX));
            //md_1.setM2Speed(-(ps2x.Analog(PSS_LX)+30));
            digitalWrite(13, LOW);  //Establishes backward direction of Channel B
            digitalWrite(8, LOW);   //Disengage the Brake for Channel B
            analogWrite(11, 165);    //Spins the motor on Channel B at half speed
           }else if(ps2x.Button(PSB_R2)){
            digitalWrite(12, LOW); //Establishes backward direction of Channel A
            digitalWrite(9, LOW);   //Disengage the Brake for Channel A
            analogWrite(3, 255);   //Spins the motor on Channel A at half speed
            //md_1.setM1Speed(-ps2x.Analog(PSS_LX));
            //md_1.setM2Speed(-(ps2x.Analog(PSS_LX)+30));
            digitalWrite(13, LOW);  //Establishes backward direction of Channel B
            digitalWrite(8, LOW);   //Disengage the Brake for Channel B
            analogWrite(11, 255);    //Spins the motor on Channel B at half speed
           }else if(ps2x.Analog(PSS_LY) == 255){ //Special command for getting max speed according to the motor shield library way of writing
            digitalWrite(12, HIGH); //Establishes forward direction of Channel A
            digitalWrite(9, LOW);   //Disengage the Brake for Channel A
            //int motorA_to_400 = (400 - ps2x.Analog(PSS_LY) ); // forward motorSpeed of A to complete 400 value for adaptation to motor shield library
            analogWrite(3, (ps2x.Analog(PSS_LY)+120) );   //Spins the motor on Channel A at full speed
            //md.setM1Speed(ps2x.Analog(PSS_LY));
            //md.setM2Speed(ps2x.Analog(PSS_LY)+30);
            digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
            digitalWrite(8, LOW);   //Disengage the Brake for Channel B
            //int motorB_to_400 = (400 - ps2x.Analog(PSS_LY) ); // forward motorSpeed of B to complete 400 value for adaptation to motor shield library
            analogWrite(11, (ps2x.Analog(PSS_LY)+120) );    //Spins the motor on Channel B at half speed
           }else if( ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) == 127){
            digitalWrite(9, HIGH); //Eengage the Brake for Channel A
            //md.setM1Speed(0);
            //md.setM2Speed(0);
            digitalWrite(8, HIGH); //Eengage the Brake for Channel B
            }else if( (ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) >= 128) || (ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) <= 126) ){
              digitalWrite(12, LOW); //Establishes forward direction of Channel A
              digitalWrite(9, LOW);   //Disengage the Brake for Channel A
              analogWrite(3, ps2x.Analog(PSS_RY));   //Spins the motor on Channel A at full speed
              //md.setM1Speed(ps2x.Analog(PSS_RY));
              //md.setM2Speed(ps2x.Analog(PSS_RY)+30);
              digitalWrite(13, LOW);  //Establishes backward direction of Channel B
              digitalWrite(8, LOW);   //Disengage the Brake for Channel B
              analogWrite(11, ps2x.Analog(PSS_RY));    //Spins the motor on Channel B at half speed
       }else{
            digitalWrite(9, HIGH); //Eengage the Brake for Channel A
            //md.setM1Speed(0);
            //md.setM2Speed(0);
            digitalWrite(8, HIGH); //Eengage the Brake for Channel B
           }

  /*
  // Motor 1 and 2 go backward 
  if( ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) == 127){
    digitalWrite(9, HIGH); //Eengage the Brake for Channel A
    //md.setM1Speed(0);
    //md.setM2Speed(0);
    digitalWrite(8, HIGH); //Eengage the Brake for Channel B
      }else if( (ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) >= 128) || (ps2x.Button(PSB_L2) && ps2x.Analog(PSS_RY) <= 126) ){
        digitalWrite(12, LOW); //Establishes forward direction of Channel A
        digitalWrite(9, LOW);   //Disengage the Brake for Channel A
        analogWrite(3, ps2x.Analog(PSS_RY));   //Spins the motor on Channel A at full speed
        //md.setM1Speed(ps2x.Analog(PSS_RY));
        //md.setM2Speed(ps2x.Analog(PSS_RY)+30);
        digitalWrite(13, LOW);  //Establishes backward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, ps2x.Analog(PSS_RY));    //Spins the motor on Channel B at half speed
       }
  */
  // Stop Motors
  if(ps2x.Button(PSB_BLUE)){
    digitalWrite(9, HIGH); //Eengage the Brake for Channel A
    //md.setM1Speed(0);
    //md.setM2Speed(0);
    digitalWrite(8, HIGH); //Eengage the Brake for Channel B
  }   

 }  


 
 delay(50);
  
}

I found the cause for trying to control dc motors with motor shield via ps2’s both joystick values for different purposes. Because the joysticks’ left and right sides’ x and y axis analog values ( PSS_LY,PSS_LX and PSS_RY, PSS_RX ) are constantly appear, even I wrote the code in logically, some codes overlapped each other. That’s why, I was not able to use both side joysticks.

I am happy to solve it ,even I was asked here to get some guidance; but I have it myself at the end^^. I wanted to let you know if someone encounter similar problem too in the future.