RF controlled robot

#include <Servo.h>

//char go_dir = 0; 
Servo servo1;
Servo servo2;

void setup(){
  
  
  Serial.begin(9600);
  servo1.attach(3);
  servo2.attach(5);
}

void loop(){
  while(Serial.available() > 0){
  char go_dir = 'e'; 
   go_dir = Serial.read();
   //Serial.println(go_dir);
  
   
   
  
   switch(go_dir){
   
   case 'w':
   straight();
   Serial.println("Moving Forward");
   break; 
   
   case 's':
   reverse();
   Serial.println("Moving Back");
   break;
   
   case 'a':
   rotateCounterclockwise();
   Serial.println("Rotating Counter Clockwise");
  break;
 
 case 'd': 
 rotateClockwise();
 Serial.println("Rotating Clockwise");
 break;
 
 case 'x':
 halt();
 Serial.println("Stopping");
 break;
   
 
 
   }
  }
}
    
  
//---------------------(FUNCTIONS)-------------------

void straight(){
  
servo1.write(0);
 servo2.write(180);
 
}

void halt(){
  servo1.write(94);
  servo2.write(95);
}

void reverse(){
  servo1.write(180);
  servo2.write(0);
}

void rotateClockwise(){
  servo1.write(0);
  servo2.write(0);
}
void rotateCounterclockwise(){
  servo1.write(180);
  servo2.write(180);
}

so what im trying to do is make a robot that i will control via a wixel tranceiver. right now im just working out the code and controlling it via the com port and a usb cable. i would like to make it so that the robot will proceed forward only while the “w” key is pressed and will stop when you stop pressing the key. i can’t come up with a way to do this. im using putty to avoid having to press enter to send data. does anyone have any suggestions?
thank you for your time

A rather crude way to control something ,but I 've done it myself when I first started out. You answer is adding a default case. If go_dir does not match any case, indicating you released the button, to stop moving.

This works well when IF Serial.available() > 0, this means you are pressing a button, and if your not pressing a button, set go_dir = to NULL or some other key your not using, then feed it back into the case statement.

Here is some test code. This is using IF/ELSE statements but can be done with case statements too.

/*
simple control test
 */

char val;         // variable to receive data from the serial port

const byte LMF = 3;// PWM LEFT MOTOR FORWARD 
const byte LMR = 5;// PWM LEFT MOTOR REVERSE
const byte RMF = 9;// PWM RIGHT MOTOR FORWARD
const byte RMR = 6;// PWM RIGHT MOTOR REVERSE
const byte ledpin = 13;


void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(LMF, OUTPUT);                                
  pinMode(LMR, OUTPUT);
  pinMode(RMF, OUTPUT);                                
  pinMode(RMR, OUTPUT);
  Serial.begin(9600);       // start serial communication at 9600bps
}

void loop() {
  if( Serial.available() > 0)       // if data is available to read
  { 
    digitalWrite(ledpin, HIGH); //Indicates your receiving a command(s)
    val = Serial.read();

    if( val == 'W' || val == 'w' )//forwards               
    {
      //Serial.println("Moving Forwards");
      digitalWrite(LMR, LOW);  
      digitalWrite(LMF, HIGH);
      digitalWrite(RMR, LOW);
      digitalWrite(RMF, HIGH);                  
    }
    else if( val == 'S' || val == 's' )//backwards              
    {
      //Serial.println("Moving Backwards");
      digitalWrite(LMF, LOW);   
      digitalWrite(LMR, HIGH);
      digitalWrite(RMF, LOW);
      digitalWrite(RMR, HIGH);                   
    }
    else if( val == 'A' || val == 'a' )//Left         
    {
      //Serial.println("LEFT");
      digitalWrite(LMF, LOW);    
      digitalWrite(LMR, HIGH);
      digitalWrite(RMR, LOW);
      digitalWrite(RMF, HIGH);                 
    }
    else if( val == 'D' || val == 'd' )              
    {
      //Serial.println("RIGHT");
      digitalWrite(LMR, LOW);   
      digitalWrite(LMF, HIGH);
      digitalWrite(RMF, LOW);
      digitalWrite(RMR, HIGH);                  
    }
    else {
    }    
  }
  digitalWrite(ledpin,LOW); // Not receiving command(s)
  digitalWrite(LMR, LOW);   
  digitalWrite(LMF, LOW);
  digitalWrite(RMF, LOW);
  digitalWrite(RMR, LOW);
}

i would like to make it so that the robot will proceed forward only while the "w" key is pressed and will stop when you stop pressing the key.

The PC can send serial data. The Arduino can read serial data. The issue is that serial data transmission can be slow, and you have no control over how often putty sends the data. It may send data as fast as the repeat rate of the key, or it may ignore the repeat information.

It's much better to write your own application to send data. Send one value when a key becomes pressed and another value when the key becomes released. For instance, W means pressed and w means released.

Then, the Arduino can just keep doing what it was told to do last time, until it is told to do something different.