How to continuously send data

Hi Guy,
My project is to control an RC car using two Arduinos. One will be attached to the car, and the other will be attached to the computer.

the program works in this way: if I press "f" in the Serial Monitor, the car will go forward.
the problem is that I have to press "f" and then enter, and the car will go forward unless I stop it by pressing another key.

How can I make my program works in this way: When I press "f", it goes forward. And when I stop pressing "f", the car stops.

Thanks a lot
continuously

Where is your circuit?
That will dictate a lot of your code.

The easiest solution is to not use the serial monitor in the Arduino IDE but rather a PC serial terminal program that allows one to send single characters out without needing a enter command or send command. There are many free avalible no matter what OS you are using.

Lefty

I'm using Xbee connection between the Arduinos. this is way I'm using the Serial Monitor.
Is it possible to use Lefty's idea with the Xbee?

Thanks Guys

The code is:
/*
MOBOT BTCar
Author: Daniel Garrote
Project: MOBOT
Project URL: www.mobot.es
*/

int forward = 12; // Pin 12 - Forward
int reverse = 11; // Pin 11 - Reverse
int left = 10; // Pin 10 - Left
int right = 9; // Pin 9 - Right

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

void setup() {

// initialize the digital pins as output
pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);

Serial.begin(9600); // Start serial communication at 9600bps
}

// Fordward action
void go_forward() {
digitalWrite(forward, HIGH);
digitalWrite(turbo, LOW);
digitalWrite(reverse, LOW);
}

// Stop Forward action
void stop_go_forward() {
digitalWrite(forward, LOW);
}

// Reverse action
void go_reverse() {
digitalWrite(reverse, HIGH);
digitalWrite(forward, LOW);
digitalWrite(turbo, LOW);
digitalWrite(reverse_lights, HIGH);
}

// Stop Reverse action
void stop_go_reverse() {
digitalWrite(reverse, LOW);
digitalWrite(reverse_lights, LOW);
}

// Left action
void go_left() {
digitalWrite(left, HIGH);
digitalWrite(right, LOW);
}

// Right action
void go_right() {
digitalWrite(right, HIGH);
digitalWrite(left, LOW);
}

// Stop turn action
void stop_turn() {
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Stop car
void stop_car() {
digitalWrite(forward, LOW);
digitalWrite(reverse, LOW);
digitalWrite(turbo, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
digitalWrite(reverse_lights, LOW);
}

// Read serial port and perform command
void performCommand() {
if (Serial.available()) {
val = Serial.read();
}
if (val == 'f') { // Forward
go_forward();
} else if (val == 'z') { // Stop Forward
stop_go_forward();
} else if (val == 'b') { // Backward
go_reverse();
} else if (val == 'y') { // Stop Backward
stop_go_reverse();
} else if (val == 'l') { // Right
go_right();
} else if (val == 'r') { // Left
go_left();
} else if (val == 'v') { // Stop Turn
stop_turn();
} else if (val == 's') { // Stop
stop_car();

}

void loop() {
performCommand();
}

If your pc is running windows, try using hyperterminal to send the characters.

I'm using Mac

For sure there is a terminal emulator for Mac that does the same, but I am not an Apple person.
If you run Linux on the Mac then you should have many-many choices.

Do you have a compiler or interpreter you can use that lets you read keys? Sometimes the best is what you write yourself. Then you don't have to have it keep sending to go forward -- you can have it send once and when you release the key, send a stop or other command. By reading the keyboard hardware you should be able to read more than one key at a time. Besides, doesn't the number pad make a better steering controller? Or a joystick?