Acknowledging a keypress

I’ve put together an engine run in program and need to have an emergency shutdown ability. It’s just another servo program with a number of entered options that run the engine through different routines. Right now the emergency shutdown looks like this:

void loop() {
// load options
while(Serial.available() <1){ // any key
// run code
}
Serial.println(“got keypress”);
emergencyStop();
}

This works but you need the enter key press for it to take action. I really want the code to respond to any key pressed without waiting for the enter. I’m pretty sure I need to watch the hardwareserial rx_buffer with an interrupt but haven’t figured out how to code it. It’s way above my coding ability right now so I could use some code samples or a pointer to some samples.

The other thought I had was having digitalread watch the Rx pin; is this doable?

Thanks in advance;
RichK

The only problem with that is.. if you're using the Arduino Serial monitor, you'll always need to push enter.

You could use Processing.org to detect key presses and then talk to the Arduino via Serial like you are.

Here's an idea of kind of how it would look.. keep in mind that Arduino and Processing are nearly identical, just give different abilities. The code will seem very familiar.

http://processing.org/reference/keyPressed_.html

Instead of the "Value == 0" and such, you could use mySerial.print("K");// send value "K" from Processing to your Arduino

And I'm afraid using Digital Read on either pin 0 or 1 won't work when trying to talk to any serial device.

Hopefully this helps with some ideas. :)

At first glance processing looks like a hand grenade to kill a fly, but I,ll take a closer look. I'm using the serial monitor right now because it's convenient. I'd rather use putty or some other terminal program but the real purpose of the program is to run in an engine. All this coding is just a tangent.

Say,how do we add code in a scroll box in posts/replies, I'm missing it somehow? RichK

Well, it's probably the easiest way I could think of someone using an Arduino.. you can use very simple code, even from the tutorials to do what you want to do.

Also, after making a "Sketch" in Processing, you an Export it to a .exe file, so it will run like a normal program, but keep in mind, you'll need to have it selected, just won't need to push enter.

For posting code, there's an icon with the '#' symbol, that's the one. Or you can just put a [ code] Code here :) / code

There are a couple other options that could open some possibilities.. GoBetwino http://www.mikmo.dk/gobetwino.html and AAC Keys (serial keyboard ) http://www.aacinstitute.org/downloads/aackeys/AACKeys.html

This will connect to an Arduino and accept Serial commands such as Serial.print("P"); // to push a Capital P on the keyboard Serial.println(); // Serial.println will push enter

I'm sure some of that is useless.. others might help, sorry for the mix up! :D