Press a button and move the joystick

Hello,

I would like to press a button and move the joystick at the same time like on the X-Box controller.
How can I realize this?

The joystick should be connected to the PC as a controller.

I use a Teensy 3.5.

thanks for your help

Flammel1007

Use one finger of your left hand on the button, and a couple fingers of the right hand (or your thumb) for the joystick.

that should work.

if that's not the question, then do yourself a favour and please read How to get the best out of this forum and modify your post accordingly

What code are you using now and what is preventing you from doing those things?

Steve

Hello,

I play the game Farming Simulator, to control the front loader there, I bought a joystick: Joystick
This I have also successfully connected to the PC, and can control the front loader.
But:
To be able to control the front loader completely, I need several axes (3) or a combination of button with axis (like the X-Box controller with LB + RX(-) or RB + RX(-)).

Unfortunately, I can currently operate either a button or the axis but not both at the same time.

So where does the Teensy 3.5 come into this story?

Steve

why haven't you posted the code?

Hello,

now it already works almost 100%

// Begin Joystick_Frontlader
int wert_Blau = 0;
int wert_Gelb = 0;
// Ende Joystick_Frontlader

void setup() {
  // Begin Taster_Frontladerhebel
  pinMode(17, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  Joystick.begin();
  // Ende Taster_Frontladerhebel
}

void loop() {
  Taste_3();
  Taste_4();
  Joystick_Frontlader();
  
}

void Taste_3(){
  Serial.println("Taste_3");
  byte Tast_3 = 0; 
  Tast_3= digitalRead(17);
  Joystick.button(1,Tast_3); 
}

void Taste_4(){
  Serial.println("Taste_4");
  byte Taste_4 = 0; 
  Taste_4= digitalRead(16);
  Serial.println("Taste4:" + Taste_4);
  Joystick.button(2,Taste_4); 
}
void Joystick_Frontlader(){
  wert_Blau = analogRead(A9) - analogRead(A8);
  wert_Gelb = analogRead(A7) - analogRead(A6); 
  bool bewegt = false;
  if(0 <= wert_Blau && wert_Blau <= 60){
      Joystick.X(512);
    }
    else if(wert_Blau < 0){
      Joystick.X(512+wert_Blau);
      bewegt = true;
    }
    else if(wert_Blau > 60){
      Joystick.X(512+wert_Blau);
      bewegt = true;
    }
  if(-60 <= wert_Gelb && wert_Gelb <= -20){
      Joystick.Y(512);
    }
    else if(wert_Gelb < -60){
      Joystick.Y(512+wert_Gelb);
      bewegt = true;
    }
    else if(wert_Gelb > -20){
      Joystick.Y(512+wert_Gelb);
      bewegt = true;
    }
    if (bewegt == true){
      Serial.println("bewegt");
      delay(50);
      Joystick.X(512);
      Joystick.Y(512);
    }
}

When I release the button, however, and only a short time later return the joystick to its initial position, my front loader continues to move in the game.

I was not at my computers

Hello,

Here is my final version that works

// Begin Joystick_Frontlader
int wert_Blau = 0;
int wert_Gelb = 0;
int rueck_3;
int rueck_4;
// Ende Joystick_Frontlader

void setup() {
  // Begin Taster_Frontladerhebel
  pinMode(17, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  Joystick.begin();
  // Ende Taster_Frontladerhebel
}

void loop() {
  Taste_3();
  Taste_4();
  Joystick_Frontlader();
}

void Taste_3(){
  byte Taste_3 = 0; 
  Taste_3 = digitalRead(17);
  if(Taste_3 == 1){
    rueck_3 = 1;
  }
  Joystick.button(1,Taste_3);
  if(Taste_3 == 0 && rueck_3 == 1){
    Joystick.button(1,1);
    Joystick.X(512);
    Joystick.Y(512);
    Joystick.button(1,0);
    rueck_3 = 0;
  }
}

void Taste_4(){
  byte Taste_4 = 0; 
  Taste_4 = digitalRead(16);
  if(Taste_4 == 1){
    rueck_4 = 1;
  }
  Joystick.button(2,Taste_4); 
  if(Taste_4 == 0 && rueck_4 == 1){
    Joystick.button(2,1);
    Joystick.X(512);
    Joystick.Y(512);
    Joystick.button(2,0);
    rueck_4 = 0;
  }
}
void Joystick_Frontlader(){
  wert_Blau = analogRead(A9) - analogRead(A8);
  wert_Gelb = analogRead(A7) - analogRead(A6); 
  bool bewegt = false;
  if(0 <= wert_Blau && wert_Blau <= 60){
      Joystick.X(512);
    }
    else if(wert_Blau < 0){
      Joystick.X(512+wert_Blau);
      bewegt = true;
    }
    else if(wert_Blau > 60){
      Joystick.X(512+wert_Blau);
      bewegt = true;
    }
  if(-60 <= wert_Gelb && wert_Gelb <= -20){
      Joystick.Y(512);
    }
    else if(wert_Gelb < -60){
      Joystick.Y(512+wert_Gelb);
      bewegt = true;
    }
    else if(wert_Gelb > -20){
      Joystick.Y(512+wert_Gelb);
      bewegt = true;
    }
    if (bewegt == true){
      Serial.println("bewegt");
      delay(30);
      Joystick.X(512);
      Joystick.Y(512);
    }
}

Or does anyone have a better solution