Go Down

Topic: Keyboard Control LED problem (Read 1 time) previous topic - next topic

I am a beginner in both programming and arduino. i am working on a project to drive a robot using inputs from a wireless keyboard. I am using a PC connected serially to the Arduino to transfer the key inputs to the dc motors. as a test run i connected the arduino to an LED and wrote the code to take the key input and turn the LED on and off. i would like to be able to press a key and have the LED light up and turn off when i release the key. so far the light turns on when i press the key and stays on until another key is pressed. i have tried inputting keystrokes from both hyperterminal and putty. any help would be greatly appriciated, my code is below

// variable to store serial data
int incomingByte = 0;


void setup(){

// Start serial monitor at 9600 bps

// declare outputs
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);

// turn LED Off by default
digitalWrite(13, LOW);




void loop(){

// check for serial data
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// if available, blink LED and print serial data received.
digitalWrite(13, HIGH);
// say what you got:
Serial.print("I received: ");
// delay 10 milliseconds to allow serial update time
        if (incomingByte == 'q' || incomingByte == 'Q')// keypress to turn on LED
         digitalWrite(12, HIGH);
       digitalWrite(12, LOW);



Do you want to use a PC in the final design?  If so, you are going to need to use a different program on the PC.  You could write a Processing program to handle the different key states, and it would talk to the Arduino.

See keyboard section: http://www.processing.org/reference/
Using the serial port: http://learning.codasign.com/index.php?title=Communicating_with_Processing_Over_Serial

I was afraid of that, i have a feeling that is beyond my programming capacity at the moment. do you know of any GUI interfaces that other people have used for this type of an application. i have found a lot of people who are doing similar projects online.

Go Up