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