Can you post your code here?
Yes, I will post it this afternoon
This is the code for the joystick
const int throttle = A9;
int throttleVal = 0;
const int propellerPitch = A8;
int propellerVal = 1023;
const int choke = A7;
int chokeVal = 0;
const int pitch = A0;
int pitchVal = 1023;
const int roll = A1;
int rollVal = 0;
#define WINDOW_SIZE 5
int rollIndex = 0;
int rollSum = 0;
int rollReadings[WINDOW_SIZE];
int rollAvg = 0;
int pitchIndex = 0;
int pitchSum = 0;
int pitchReadings[WINDOW_SIZE];
int pitchAvg = 0;
// Theses are the pins for the linear pot
//pin #3 = 3V
//pin #1 = GND
//pin #2 = output
void setup() {
pinMode(throttle, INPUT_PULLUP);
pinMode(propellerPitch, INPUT_PULLUP);
pinMode(choke, INPUT_PULLUP);
pinMode(pitch, INPUT_PULLUP);
pinMode(roll, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
throttleVal = analogRead(throttle);
propellerVal = analogRead(propellerPitch);
chokeVal = analogRead(choke);
pitchVal = map(analogRead(pitch), 300, 880, 0, 1023);
rollVal = map(analogRead(roll), 264, 850, 0, 1023);
rollSum = rollSum - rollReadings[rollIndex]; // Remove the oldest entry from the sum
rollReadings[rollIndex] = rollVal; // Add the newest reading to the window
rollSum = rollSum + rollVal; // Add the newest reading to the sum
rollIndex = (rollIndex+1) % WINDOW_SIZE; // Increment the index, and wrap to 0 if it exceeds the window size
rollAvg = rollSum / WINDOW_SIZE;
pitchSum = pitchSum - pitchReadings[pitchIndex]; // Remove the oldest entry from the sum
pitchReadings[pitchIndex] = pitchVal; // Add the newest reading to the window
pitchSum = pitchSum + pitchVal; // Add the newest reading to the sum
pitchIndex = (pitchIndex+1) % WINDOW_SIZE; // Increment the index, and wrap to 0 if it exceeds the window size
pitchAvg = pitchSum / WINDOW_SIZE;
Serial.println("Throttle: " + throttleVal);
Serial.println("Propeller Pitch: " + propellerVal);
Serial.println("Choke: " + chokeVal);
Serial.print(pitchAvg);
Serial.print(",");
Serial.println(rollAvg);
Joystick.sliderLeft(throttleVal);
Joystick.sliderRight(propellerVal);
Joystick.Zrotate(chokeVal);
}
And this is the code for the buttons. (I need to combine them still.)
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
}
const int pinToButtonMap = -1;
int lastButtonState[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void loop() {
for (int index = 0; index < 11; index++) {
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index]) {
Joystick.button(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}
Are you using just buttons, or are you also using a yoke and throttle with this code?
I’m using a custom stick with the first bit of code. I am working on making a full cockpit of the CubCrafters XCub/NXCub and everything in the cockpit is run through a Teensy LC. The stick uses two Hal effect sensors and the throttle and propeller pitch use rotary potentiometer and the choke uses a linear potentiometer. And then the ten switches are just basic single pull single throw and I have tested them using the second bit of code. I am still working on designing the rudder pedals and brakes and the starter.
That sounds awesome. Have you tried testing the code in sections to pinpoint the possible error? It is possible and just a small section in not working properly.
I have an Arduino Pro Micro and I get the same error. Were you able to fix this issue? If so, what is the solution?
I have the same issue. I have used the code that JBDaSimmer posted. I also tried to include the Joystick.h library, but that didn’t work either. I’m running an Arduino Pro Micro.
Also consider MobiFlight, which connects to the sim via SimConnect and WASM. It has excellent firmware for Arduinos and supports switches, LEDs, buttons, encoders, 7 segment and LCD displays, servos, steppers and analog inputs.
It can control the miniCockpit FCU and WingWing devices also.
The HubHop website has over 25,000 presets for simvars to use in MobiFlight - one can even trigger Microsoft’s RPN sim language from a button.
It’s fun to write your own code, I developed 6502 code 40 years ago, but these days MobiFlight is a very efficient use of my time.