Coding for x&y axis

Hello,
I got no coding skills. I uploaded below ready code to Leonardo to use with only x and y axis pots of the Logitech Flight Yoke.
Original board in the box causes dead zone in the middle.

My question: Is this code ok for my purpose and if yes, which pins should I use on Leonardo.
A0 A1 & (3.3 or 5V) GND?

Some help much appreciated.

FLIGHT YOKE CODE:

// Requires Arduino Joystick Library https://github.com/MHeironimus/ArduinoJoystickLibrary
#include <Joystick.h>
Joystick_ Joystick;
 
int JoystickX;
int JoystickY;
int JoystickZ;
int Throttle;
int Rudder;
int Aux1;
int Aux2;
int currentButtonState0;
int lastButtonState0;
int currentButtonState1;
int lastButtonState1;
int currentButtonState2;
int lastButtonState2;
int currentButtonState3;
int lastButtonState3;
int currentButtonState4;
int lastButtonState4;
int currentButtonState5;
int lastButtonState5;
int currentButtonState6;
int lastButtonState6;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
// Initialize Joystick Library
  Joystick.begin();
  Joystick.setXAxisRange(0, 965); 
  Joystick.setYAxisRange(192, 522);
  Joystick.setZAxisRange(143, 735);
  Joystick.setRxAxisRange(158, 456);
  Joystick.setRyAxisRange(158, 456);
  Joystick.setThrottleRange(154, 448);
}

void loop() {

// Read Joystick
  JoystickX = analogRead(A0);
  JoystickY = analogRead(A1);
  JoystickZ=analogRead(A8);
  Throttle=analogRead(A2);
  Aux1=analogRead(A9);
  Aux2=analogRead(A3);
  Serial.print(JoystickX);
  Serial.print("   ");
  Serial.print(JoystickY);
  Serial.print("   ");
  Serial.println(JoystickZ);


// Read Switches
int currentButtonState0 = !digitalRead(2); // Button 0
  if (currentButtonState0 != lastButtonState0)
  {
  Joystick.setButton(0, currentButtonState0);
  lastButtonState0 = currentButtonState0;
  }

int currentButtonState1 = !digitalRead(3); // Button 1
  if (currentButtonState1 != lastButtonState1)
  {
  Joystick.setButton(1, currentButtonState1);
  lastButtonState1 = currentButtonState1;
  }
  
int currentButtonState2 = !digitalRead(4); // Button 2
  if (currentButtonState2 != lastButtonState2)
  {
  Joystick.setButton(2, currentButtonState2);
  lastButtonState2 = currentButtonState2;
  }

int currentButtonState3 = !digitalRead(5); // Button 3
  if (currentButtonState3 != lastButtonState3)
  {
  Joystick.setButton(3, currentButtonState3);
  lastButtonState3 = currentButtonState3;
  }
  
int currentButtonState4 = !digitalRead(6); // Button 4
  if (currentButtonState4 != lastButtonState4)
  {
  Joystick.setButton(4, currentButtonState4);
  lastButtonState4 = currentButtonState4;
  } 

int currentButtonState5 = !digitalRead(7); // Button 5
  if (currentButtonState5 != lastButtonState5)
  {
  Joystick.setButton(5, currentButtonState5);
  lastButtonState5 = currentButtonState5;
  } 
  
   
// Output Controls
  Joystick.setXAxis(JoystickX);
  Joystick.setYAxis(JoystickY);
  Joystick.setZAxis(JoystickZ);
  Joystick.setThrottle(Throttle);
  Joystick.setRxAxis(Aux1);
  Joystick.setRyAxis(Aux2);
  Joystick.sendState();

}

Is this code ok for my purpose

You're the only person who can answer that!

Please remember to use code tags when posting code.

TheMemberFormerlyKnownAsAWOL:
You're the only person who can answer that!

Please remember to use code tags when posting code.

Sorry, will do next time.

ndursun:
Sorry, will do next time.

Do it now. You know you want to

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

UKHeliBob:
Do it now. You know you want to

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

Ok. I managed my part done. Now it's your turn. I'm the noob you're the pro. Help..

The debouncing code looks a bit . . . short-term.

What seems to be the problem?

Edit: not debouncing, just state-change, sorry.

The code is very wordy and has potential scope issues - did you change it, or is that how it was published?

I just loaded the ready file through Arduino IDE library and uploaded to Leonardo.

I did not change any part of the code while doing this.

I think code contains all the axis plus the buttons but actually I only need only the x & y axis part of it.

I am not able to exclude the rest of the code. If only I could have the axis only file, I would upload
it and try to test the connection pins of Leonardo whether it works or not.

ndursun:
I am not able to exclude the rest of the code.

Is this some kind of copyright issue?

No, Its only that I never did coding.

But I can ride my Triumph Trophy fast as hell :grinning:

Which one is the Trophy?

TheMemberFormerlyKnownAsAWOL:
Which one is the Trophy?

1200 SE 2014
https://www.google.com/url?sa=i&url=https%3A%2F%2Fbikez.com%2Fmotorcycles%2Ftriumph_trophy_se_2014.php&psig=AOvVaw1wMb45b11d7CTc6TlhCg7I&ust=1611167308534000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCNjhxZLQqO4CFQAAAAAdAAAAABAD

Apologize all!

Consider this problem as resolved.

Its going to turn this area to a a little bit of flooding
(which I hate) with non related chat.

Better I connect the card as it is and see whether it works or fries. Then try another one.

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