Pages: [1]   Go Down
Author Topic: Keyboard Control LED problem  (Read 1034 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Serial.begin(9600);

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

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

delay(500);

}

//

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: ");
Serial.println(incomingByte);
// delay 10 milliseconds to allow serial update time
delay(10);
       
        if (incomingByte == 'q' || incomingByte == 'Q')// keypress to turn on LED
        {
         digitalWrite(12, HIGH);
        }
else
       digitalWrite(12, LOW);

}}

Logged

USA
Offline Offline
Full Member
***
Karma: 0
Posts: 235
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: