how to control motor dc using controller ps2

hi everyone.
i’d want to make a project, that could control the motor dc using joystick from ps2.
first i use a motor dc, with a transistor, resistor and dioda to connect to arduino. Meanwhile, the controller ps2 is connected to arduino.
The sticks value from joystick ps2 are being read by the arduino, but my motor wouldnt stop spinning.
and, here its my code.

#include <PS2X_lib.h>
#define PS2_DAT        13  //14    
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17
//#define pressures   true
#define pressures   false
//#define rumble      true
#define rumble      false

PS2X ps2x;
byte motor1=5;
int speed =128;
int error =0;
byte type = 0;
byte vibrate = 0;
int RX=0,RY=0,LX=0,LY=0;

void setup(){
 
  Serial.begin(57600);
  
  delay(300); 
  pinMode (motor1,OUTPUT);
  //added delay to give wireless ps2 module some time to startup, before configuring it
   
  //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
  
  //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);
  
  if(error == 0){
    Serial.print("Found Controller, configured successful ");
    Serial.print("pressures = ");
  if (pressures)
    Serial.println("true ");
  else
    Serial.println("false");
  Serial.print("rumble = ");
  if (rumble)
    Serial.println("true)");
  else
    Serial.println("false");
    Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
    Serial.println("holding L1 or R1 will print out the analog stick values.");
    Serial.println("Note: Go to www.billporter.info for updates and to report bugs.");
  }  
  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
   
  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
  
//  Serial.print(ps2x.Analog(1), HEX);
  
  type = ps2x.readType(); 
  switch(type) {
    case 0:
      Serial.print("Unknown Controller type found ");
      break;
    case 1:
      Serial.print("DualShock Controller found ");
      break;
    case 2:
      Serial.print("GuitarHero Controller found ");
      break;
  case 3:
      Serial.print("Wireless Sony DualShock Controller found ");
      break;
   }
}

void loop ()
{
  ps2x.read_gamepad();
 if((ps2x.Analog(PSS_RY) < 128))
  {
     speed =map(ps2x.Analog(PSS_RY), 0 , 128, 0 , 255);
     analogWrite(motor1, speed);   
     digitalWrite(motor1,LOW);
     delay (50);
   }

   else {
     digitalWrite(motor1, LOW);
     digitalWrite(motor1,LOW);
     delay (50);
     
   } 
   Serial.print("Stick Values:");
   Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX  
   Serial.print(",");
   Serial.print(ps2x.Analog(PSS_LX), DEC); 
   Serial.print(",");
   Serial.print(ps2x.Analog(PSS_RY), DEC); 
   Serial.print(",");
   Serial.println(ps2x.Analog(PSS_RX), DEC); 
    delay(50);
}

i hope everyone here could help me, because i already opened may source, but couldnt get the answer

What values are you getting from the joystick? What motor are you using? How is it wired up?

analogWrite(motor1, speed);
digitalWrite(motor1,LOW);

Seems wrong, you turn the motor on at a certain speed to immediately turn it off again.

If your motor driving circuit inverts the signal, it will always be on.
So please include a wiring diagram, and open the serial monitor to see what values you are getting, like INTP said.

INTP:
What values are you getting from the joystick? What motor are you using? How is it wired up?

when the joystick isnt pushed the value are 128, but when the joystick pushed are 0 for one axis like RY.
im using general motor dc 6v, which usually used in small robot

then, what supposed i write the code? please explain it for me, because im really a newbie here.

i followed this tutorial and apply it on my arduino

and here its my wiring

here its the serial monitor of my arduino

its, before the joystick are pushed

and this after the joystick are pushed

First, check that the motor and transistor are wired correctly.
Remove the orange wire from the Arduino and connect it to ground.
The motor should not run.
Connect it to +5V. The motor should run at full speed.
If that is working,
remove the line digitalWrite(motor1,LOW);
after the analogWrite.
I doubt it is doing anything good as PieterP says.
I don't see it in any of the examples.
The joy stick looks to be reversed. In your map swap the first 0,128 or the second 0,255.
to read like this for the first 0,128:

speed =map(ps2x.Analog(PSS_RY), 128 , 0, 0 , 255);

Report back when done.
Dwight

Map parameter order should be fine, those PS2 joystick modules can have the Y axis with 0 at the top and SHOULD be 1023 at the bottom, why he's only reading 128 is beyond me.

INTP:
Map parameter order should be fine, those PS2 joystick modules can have the Y axis with 0 at the top and SHOULD be 1023 at the bottom, why he's only reading 128 is beyond me.

I think he wanted stop at the bottom and run at the top.
At least that is consistent with his comments.
Dwight