Bluetooth as a push button

This is the code to control 2 motors with a Bluetooth module the problem is that when the Serial receives a letter, let's say "s" it stays inside the loop forever and the motors keep on moving, what I want is that when the Bluetooth serial communication I want my motors to move just when the "s" is being kept pressed, like a push button or a remote control. Do you have any solutinos that worked for you? Suggestions on what to try?

Thanks in advance!

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/
#include <SoftwareSerial.h>// import the serial library
//bluetooth config
SoftwareSerial Genotronex(9, 10); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int ledpin2 = 12;
int BluetoothData; // the data given from Computer

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position

//motors port config

int motor1a=2;
int motor1b=3;
int motor2a=4;
int motor2b=5;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(motor1a, OUTPUT);
pinMode(motor1b, OUTPUT);
pinMode(motor2a, OUTPUT);
pinMode(motor2b, OUTPUT);
myservo.attach(11); // attaches the servo on pin 9 to the servo object

}

// the loop routine runs over and over again forever:
void loop() {
//recibir bits bluetooth
if (Genotronex.available())
{
BluetoothData=Genotronex.read();

}
if (BluetoothData == 's')
{
//atras
digitalWrite(motor2a, HIGH);
digitalWrite(motor2b, LOW);
digitalWrite(motor1a, HIGH);
digitalWrite(motor1b, LOW);

}
else if (BluetoothData == 'w')
{
//frente
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, HIGH);
digitalWrite(motor1a, LOW);
digitalWrite(motor1b, HIGH);
}
else if (BluetoothData == 'a')
{
//izquierda
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, HIGH);
digitalWrite(motor1a, HIGH);
digitalWrite(motor1b, LOW);
}
else if (BluetoothData == 'd')
//derecha
{
digitalWrite(motor2a, HIGH);
digitalWrite(motor2b, LOW);
digitalWrite(motor1a, LOW);
digitalWrite(motor1b, HIGH);
}
else
{
digitalWrite(motor1a,LOW);
digitalWrite(motor1b,LOW);
digitalWrite(motor2a,LOW);
digitalWrite(motor2b,LOW);
}

// print out the value you read:
delay(1); // delay in between reads for stability
}

the problem is that when the Serial receives a letter, let's say "s" it stays inside the loop forever and the motors keep on moving,

It doesn't have to. Simply set BluetoothData to ' ', after using the value.

It gives me a invalid conversion error, my BluetoothData variable is set as an integer, and if I change it to string, then it throws an error in the Genotronex.read() line.

my BluetoothData variable is set as an integer

Your bluetooth module should be sending out chars, not ints.
But I can see where the problem is and it's with this line here, "int BluetoothData; // the data given from Computer"
BluetoothData should be type char not int. In fact you're already comparing it to chars in your IF statements.

BluetoothData == 's'

All you need to do now is make it so a space char is sent out when no button/key is pressed.

All you need to do now is make it so a space char is sent out when no button/key is pressed.

Not a good idea. How will you determine how often to send the space?

What is needed is to set BluetoothData to some value that is not a valid "command" after processing that one "command".

my BluetoothData variable is set as an integer, and if I change it to string

A string is a NULL terminated ARRAY of chars. No one suggested changing the type to string. Change it co char - ONE char. Or set the value to -27.

Not a good idea. How will you determine how often to send the space?

Well it could just be as simple as checking to see if any key is pressed or not. If a key (wasd) is pressed then send it out, otherwise send out something that isn't one of the keys the code is looking for. He can code it to just send out one stop key or a continuous stream. He could even press 'x' and send it out to stop the motors.

Its up to him as to what he wants to do. Also he didn't say what he was using to send the chars in the first place, so he could already be sending out a NULL char and just not be looking for it. Who knows. :confused: