An exotic way to control the LED with PC's k-board

Hello!
I have a task - to make my Ardi turn on the Led while I hold a key on the keyboard, and turn off it when I release the key.

I suppose there is special function in c++\wiring that monitors pressing of the key, so I have already complete sketch minus this weird function.

Here it is:

int outputPin = 13;
int val;

void setup() {
Serial.begin(9600);
pinMode(outputPin, OUTPUT);
}

void loop()
{
val = 0;
if (---???---)
val = 1; // if button is holded...
else
val = 0; // if not.

if (val == 0) {
digitalWrite(outputPin, LOW);
}
if (val == 1) {
digitalWrite(outputPin, HIGH);
}
}

Instead of '---???---' I think must be a function that detects button is holding.

Could you tell me what function is it?
Or suggest another algorithm, please.

P.S. Sorry for my english.. :smiley:

I have a task - to make my Ardi turn on the Led while I hold a key on the keyboard, and turn off it when I release the key.

The keyboard of your Arduino? What kind of keyboard do you have attached to the Arduino?

PaulS
subj: An exotic way to control the LED with PC's k-board

Arduino is connected to PC via USB and KB connected (also to PC) via PS/2.
=)

The Arduino does not have access to the PC's peripherals, including the keyboard. So, no you can't directly do what you want.

You could write an application, using C, C++, C#, Java, or some other language that monitors the keyboard, and sends serial data that the Arduino could read. When a key is pressed (any key?), send a message to the serial port ("Help, I'm being fat-fingered!").

Have the Arduino look for serial data. When it sees the correct stuff, read it and turn the LED on.

Have the PC application send another message when the key is released ("Thank dog that finger went away").

Have the Arduino turn the LED off when that message is received.

Of course, you could make it easier to know what to do by just sending 0 or 1, but where's the fun in that.

If you haven't installed Processing (http://Processing.org), now would be a good time to do so. There are even example programs that handle key presses, mouse movement, serial data transmission, etc. You could have this done before the weekend gets here.

PaulS
I use ArduinoIDE to write sketches and to write them onboard. And I use MS Hyperterminal when I need to give commands to the device. In this way I tested an example Physical Pixel, which worked fine (pressing H on kb made the led turn on, and pressing L - turn off).

Now I want to modify this program a bit, where pressing and holding for ex. SPACE button should make the led shine non-stop, and releasing SPACE - make the led turned off.

I can't do this myself simply because i don't know c++ good enough..

So I'm searching a code that could detect pressing and holding of kb's keys (any 1 key).
Thanks.

Processing has examples that can detect when a key is pressed, and when a key is released.

When a key is pressed, send an H. When it is released, send an L.

PaulS

The Arduino does not have access to the PC's peripherals, including the keyboard. <<
By the way, russian guys found a way to connect PC-keyboard directly to Ardi ))
http://rln.nnov.ru/index.php?ind=reviews&op=entry_view&iden=169
enjoy)

Ok, tomorrow I'll get the Processing.