processing arduino connection difficulty

i am trying to send char's from processing to arduino, but arduino only recognizes 2 of them, i don't know were the problem is
when i press the 'w' i can see the arduino rx led lighting but the motor does nothing, i guess it is something in the arduino code, but i don't know what

arduino code:

int motor1 = 4;
int motor2 = 5;
char val; 

// --------------------------------------------------------------------------- Setup
void setup() {
Serial.begin(9600);

// Setup motors

pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);

}


// --------------------------------------------------------------------------- Loop
void loop() { 
  if (Serial.available()>0) 
   { // If data is available to read,
     val = Serial.read(); // read it and store it in val
   }
  if (val == '2'){
       drive_forward();
        }
  if (val == '1'){
      drive_inpoi();
                  }
  if (val == '0'){
  motor_stop();

                  }

}

// --------------------------------------------------------------------------- Drive

void motor_stop(){
 
digitalWrite(motor1, LOW); 
digitalWrite(motor2, LOW);


}
void drive_forward(){
 
digitalWrite(motor1, HIGH); 
digitalWrite(motor2, LOW); 
delay(15);
digitalWrite(motor1, LOW); 
digitalWrite(motor2, LOW);
delay(15);

  
}
void drive_inpoi(){
 
digitalWrite(motor2, HIGH); 
digitalWrite(motor1, LOW); 
delay(15);
digitalWrite(motor2, LOW); 
digitalWrite(motor1, LOW);
delay(15);

  
}

processing code:

import processing.serial.*;

Serial myPort;  


void setup() 
{
  size(200,200); 
  myPort = new Serial(this, Serial.list()[2], 9600);

  
}
void draw() {
                    
      
  
  

  } 
void keyPressed() {
    if (key == 'w' || key == 'W')
    { 
      myPort.write('1');
    println("1");}
      if (key == 's' || key == 'S')
    { 
      myPort.write('2');
    println("2");}
}
void keyReleased() {
myPort.write('0');
println("0");
}

when i press the 'w' i can see the arduino rx led lighting but the motor does nothing,

Why do you expect it to? If you send a 2, you could reasonably expect the Arduino to run the motors in the forward direction (whatever that means for a motor that simply rotates). If you send a 1, you could reasonably expect the Arduino to run the motors in the inpoi direction (whatever that means for a motor that simply rotates). If you send a 0, you could reasonably expect the Arduino to stop the motors. If you send any other character, you can reasonably expect the Arduino to do nothing.

i am pressing the "w" key and the processing code is sending the '1' char, not the 'w'char, at least this is what i suppose the processing code should do
actually the problem is when i'm trying to send the '2' that corresponds to the "s" key in processing
with the 1' or '0' chars i have no problem

you are telling me that there is nothing wrong with the arduino code?

Have you verified that the motor is working properly? As in, strip all the Serial stuff out and check if you can make the motor turn the right way just by calling drive_forward.

Also, fix your indenting in the Processing sketch. Those ifs are horrible.

i am not a programmer so i don't know what do you mean by fixing the indenting in the Processing sketch.

with the '1' or '0' chars i have no problem, they work , when i press the key that corresponds to the '1' char the motor does what the arduino code tells it to do.
the problem is only when sending the '2' char.

i switched the '2' in the arduino code to correspond to drive_forward and then to drive_inpoi, but the one that had '2' char assigned to it did not work in both cases,
as i said the '1'and '0' char are sent and received well