A Simple Keyboard Question

Hi all!

I am building a flight simulator cockpit, and I have three knobs/rotary encoders which I am trying to interface. None of the arduino-native programs designed to interface arduino to fsx work, as they can't communicate with the aircraft I am using. So, I have a different idea:

I would like to program each encoder so that it will send a keystroke when turned. i.e. turning encoder 1 to the left sends "q" and turning encoder 1 to the right sends "a".

I already have a script that uses serial.print to desplay each turn on the serial monitor:

#include "math.h"
#include "Quadrature.h"
Quadrature quad1(2, 3);
Quadrature quad2(4, 5);
Quadrature quad3(6, 7);

long Xold1;// the first encoder "old" reading
long Xold2;// the second encoder "old" reading
long Xold3;// the third encoder "old" reading

void setup() {
Serial.begin(115200);
}

void loop() {
long X1 =(quad1.position());
if (X1 != Xold1){
if (X1 > Xold1) {Serial.print("D740");}
if (X1 < Xold1) {Serial.print("D750");}
Xold1 = X1; // overwrites the old reading with the new one.
}//end of quad1 read

long X2 =(quad2.position());
if (X2 != Xold2){
if (X2 > Xold2) {Serial.print("D760");}
if (X2 < Xold2) {Serial.print("D770");}
Xold2 = X2; // overwrites the old reading with the new one.
}//end of quad2 read

long X3 =(quad3.position());
if (X3 != Xold3){
if (X3 > Xold3) {Serial.print("D780");}
if (X3 < Xold3) {Serial.print("D790");}
Xold3 = X3; // overwrites the old reading with the new one.
}//end of quad3 read

}

If this program could be used at all, that would be great as well.

Thanks in advance!

Steve

If you don't mind to do simple simple circuit like :
http://www.mindspring.com/~tom2000/Delphi/Quad_Decoder_4013.gif
That way the Direction decode done by hardware

  1. Let's name each output as : 'Negative' and 'Positive' respectively
  2. Let's name each set (encoder+circuit) as :
    a. Yaw
    b. Pitch
    c. Roll
  3. Use of PinChangeInt
  4. Here is what in my mind
#include <PinChangeInt.h>
#define PinYawPos 3
#define PinYawNeg 4
#define PinPitchPos 6
#define PinPitchNeg 7
#define PinRollPos 6
#define PinRollNeg 7
void setup() {
    pinMode(PinYawPos, INPUT); 
    digitalWrite(PinYawPos, HIGH);
    PCintPort::attachInterrupt(PinYawPos, YawPos, CHANGE); 

    pinMode(PinYawNeg, INPUT);
    digitalWrite(PinYawNeg, HIGH);
    PCintPort::attachInterrupt(PinYawNeg, YawNeg, CHANGE); 

    pinMode(PinPitchPos, INPUT); 
    digitalWrite(PinPitchPos, HIGH);
    PCintPort::attachInterrupt(PinPitchPos, PitchPos, CHANGE); 

    pinMode(PinPitchNeg, INPUT);
    digitalWrite(PinPitchNeg, HIGH);
    PCintPort::attachInterrupt(PinPitchNeg, PitchNeg, CHANGE); 

    pinMode(PinRollPos, INPUT);
    digitalWrite(PinRollPos, HIGH);
    PCintPort::attachInterrupt(PinRollPos, RollPos, CHANGE); 

    pinMode(PinRollNeg, INPUT);
    digitalWrite(PinRollNeg, HIGH);
    PCintPort::attachInterrupt(PinRollNeg, RollNeg, CHANGE); 

    Serial.begin(115200);
    Serial.println("Yaw Pitch Roll");
}

void loop(){}
void YawPos(){
    Serial.println("Y+");
}
void YawNeg(){
    Serial.println("Y-");
}
void PitchPos(){
    Serial.println("P+");
}
void PitchNeg(){
    Serial.println("P-");
}
void RollPos(){
    Serial.println("R+");
}
void RollNeg(){
    Serial.println("R-");
}