Arduino Throttle Joystick

I am currently working on a project where I'm trying to design and make my own throttle quadrant for flight simulator using Arduino for programming. However, I am very novice at programming and unsure what to do so I downloaded the Joystick library by Martini and tried to use already scripted code from a different throttle quadrant project by Fergobrick on Thingiverse. Flight Simulator - Throttle Quadrant/Pedestal - 737 inspired by Fergobirck - Thingiverse

Although the code works well for him I cannot replicate the same result. When I verify the code I get this error:

'Joystick_' does not name a type; did you mean 'Joystick'?

I even attempted making my own code based off his but just continue to get even more errors. My quadrent only has a Left and Right throttle with no gear switch or flap or spoiler axis and I am using an Arduino Mega 2560 with two 50k potentiometers.

#include <Joystick.h>

Joystick joystick(A1, A2);

//CALIBRATION
const int THROTTLE_LEFT_MIN = 159;
const int THROTTLE_LEFT_MAX = 497;

const int THROTTLE_RIGHT_MIN = 637;
const int THROTTLE_RIGHT_MAX = 309;

const int REVERSE_LEFT_MIN = 150;
const int REVERSE_LEFT_MAX = 70;

const int REVERSE_RIGHT_MIN = 639;
const int REVERSE_RIGHT_MAX = 719;



int axisLimits0[] = {0, 1023};
int axisLimits1[] = {0, 1023};
int axisLimits2[] = {0, 1023};
int axisLimits3[] = {0, 1023};
int axisLimits4[] = {0, 1023};
int axisLimits5[] = {0, 1023};

bool a0Used = false;
bool a1Used = false;
bool a2Used = true;
bool a3Used = true;
bool a4Used = false;
bool a5Used = false;

//PIN SETUP
const int THROTTLE_LEFT_PIN = A1;
const int THROTTLE_RIGHT_PIN = A2;

//ADC VARIABLES
int oldThrottleLeft = -1;
int oldThrottleRight = -1;

int oldThrottleLeftMapped = -1;
int oldThrottleRightMapped = -1;

int throttleLeftMapped = 0;
int throttleRightMapped = 0;


void setup() {
  if(a0Used) pinMode(A0, INPUT);
  if(a1Used) pinMode(THROTTLE_LEFT_PIN, INPUT);
  if(a2Used) pinMode(THROTTLE_RIGHT_PIN, INPUT);
  if(a3Used) pinMode(A3, INPUT);
  if(a4Used) pinMode(A4, INPUT);
  if(a5Used) pinMode(A5, INPUT);

  Joystick.setXAxisRange(0, 1023);
  Joystick.setYAxisRange(0, 1023);

  Joystick.begin();
}

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

void loop() {
  //Throttle
  int throttleleft = analogRead(THROTTLE_LEFT_PIN);

  if (throttleLeft != oldThrottleLeft) {
    oldThrottleLeft = throttleLeft;

    //Forward
    if (throttleLeft <= REVERSE_LEFT_MIN) {
      throttleLeft = constrain(throttleLeft, THROTTLE_LEFT_MIN, THROTTLE_LEFT_MAX);
      throttleLeftMapped = map(throttleLeft, THROTTLE_LEFT_MAX, THROTTLE_LEFT_MIN, AXIS_LOW, AXIS_HIGH);

      if (oldThrottleLeftMapped != throttleLeftMapped) {
        Joystick.setXAxis(throttleLeftMapped);
        Joystick.setRxAxis(0);

        oldThrottleLeftMapped = throttleLeftMapped;
      }
      
    //Reverse
    } else {
      throttleLeft = constrain(throttleLeft, REVERSE_LEFT_MIN, REVERSE_LEFT_MAX);
      throttleLeftMapped = map(throttleLeft, REVERSE_LEFT_MIN, REVERSE_LEFT_MAX, AXIS_LOW, AXIS_HIGH);

      if (oldThrottleLeftMapped != throttleLeftMapped) {
        Joystick.setXAxis(0);
        Joystick.setRxAxis(throttleLeftMapped);
        
        oldThrottleLeftMapped = throttleLeftMapped;
      }
    }
  }

  int throttleRight = analogRead(THROTTLE_RIGHT_PIN);

  if (throttleRight != oldThrottleRight) {
    oldThrottleRight = throttleRight;

    if (throttleLeft <= REVERSE_RIGHT_MIN) {
      throttleRight = constrain(throttleRight, THROTTLE_RIGHT_MIN, THROTTLE_RIGHT_MAX);
      throttleRightMapped = map(throttleRight, THROTTLE_RIGHT_MAX, THROTTLE_RIGHT_MIN, AXIS_LOW, AXIS_HIGH);

      if (oldThrottleRightMapped != throttleRightMapped) {
        Joystick.setYAxis(throttleRightMapped);
        Joystick.setRyAxis(0);
        
        oldThrottleRightMapped = throttleRightMapped;
      }
    } else {
      throttleRight = constrain(throttleRight, REVERSE_RIGHT_MIN, REVERSE_RIGHT_MAX);
      throttleRightMapped = map(throttleRight, REVERSE_RIGHT_MIN, REVERSE_RIGHT_MAX, AXIS_LOW, AXIS_HIGH);
      
      if (oldThrottleRightMapped != throttleRightMapped) {
        Joystick.setYAxis(0);
        Joystick.setRyAxis(throttleRightMapped);
        
        oldThrottleRightMapped = throttleRightMapped;
      }
     }
  }
 Serial.println(oldSpoiler);
  
  delay(50);
}

Not really spotting the issue You describe that's a compiler error, I found this code difficult. Suppose the reading is varying by as little as one bit, the if statement will trigger. Better is to use an interval checking if the new analogue value is more than a certain "distance" away like 5, 10... units different.

Can You post the error report?

Joystick is not the same as joystick

There’s something to check for.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.