[Conseil]je ne parvient pas a ajouter des bouton

bonjour,je tente de crée une commande supplémentaire pour un volant g920 sur pc avec un Leonardo je veut mettre 11 bouton et 2 joystick le tout reconnue en tant que contrôleur de jeux USB,jusque la,j’ai réussie a faire fonctionner les 2 joystick reconnue en contrôleur de jeux USB ,mais les bouton je n’arrive pas a les ajouter au programme existant,j’ai copier/coller des script que j’ai trouver dans d’autre topic(https://forum.arduino.cc/index.php?topic=398112.0) mais rien ne marche,le résultat final (qui ne marche pas)
C’est ça.

#include <Gamepad.h>
#include "simpleBouton.h"
#define BOUTON2 13
#define BOUTON3 12
#define BOUTON4 11
#define BOUTON5 10
#define BOUTON6 9
#define BOUTON7 8
#define BOUTON8 7
#define BOUTON9 6
#define BOUTON10 5
#define BOUTON11 4
#define BOUTON12 3
#define BOUTON13 2

//initialize a centers of axises for calibration
int rightXcenter = 500;
int rightYcenter = 500;
int leftXcenter = 500;
int leftYcenter = 500;
double multiplierRX = 0.254; //127 / 500
double multiplierRY = 0.254;
double multiplierLX = 0.254;
double multiplierLY = 0.254;
void clic() {Serial.println("clic");}
//Initializing a Gamepad
Gamepad gp;
void setup() {
  //initializing inputs
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);


}

  Serial.begin(115200);
   bouton.attacher(clic);
}

pinMode (BOUTON2, INPUT_PULLUP);
pinMode (BOUTON3, INPUT_PULLUP);
pinMode (BOUTON4, INPUT_PULLUP);
pinMode (BOUTON5, INPUT_PULLUP);
pinMode (BOUTON6, INPUT_PULLUP);
pinMode (BOUTON7, INPUT_PULLUP);
pinMode (BOUTON8, INPUT_PULLUP);
pinMode (BOUTON9, INPUT_PULLUP);
pinMode (BOUTON10, INPUT_PULLUP);
pinMode (BOUTON11, INPUT_PULLUP);
pinMode (BOUTON12, INPUT_PULLUP);
pinMode (BOUTON13, INPUT_PULLUP);
void loop() {
  int lx, ly, rx, ry;
  lx = analogRead(A3);
  ly = analogRead(A2);
  rx = analogRead(A1);
  ry = analogRead(A0);
  //we need to convert a 0-1000 to -127 - 127
  lx = floor((lx - leftXcenter) * multiplierLX);
  ly = floor((ly - leftYcenter) * multiplierLY);
  rx = floor((rx - rightXcenter) * multiplierRX);
  ry = floor((ry - rightYcenter) * multiplierRY);
  if(lx > 127) lx = 127;
  if(ly > 127) ly = 127;
  if(rx > 127) rx = 127;
  if(ry > 127) ry = 127;
  gp.setLeftXaxis(lx);
  gp.setRightXaxis(rx);
  //because i have placed a thumbstick in breadboard, i must invert a Y axis and swap X and Y axises
  gp.setLeftYaxis(ly);
  gp.setRightYaxis(ry);
  
  int rightStickButton, leftStickButton;
  rightStickButton = digitalRead(3);
  leftStickButton = digitalRead(4);
  
  if(rightStickButton == LOW)
	  gp.setButtonState(11, true);
  else
	  gp.setButtonState(11, false);

  if(leftStickButton == LOW)
	  gp.setButtonState(10, true);
  else
	  gp.setButtonState(10, false);

  delay(20);
}

void calibrate()
{
  int lx, ly, rx, ry;
  int i = 0;
  while(i < 8)
  {
    lx = analogRead(A3);
    ly = analogRead(A2);
    rx = analogRead(A1);
    ry = analogRead(A0);
    bool validLX = lx > (leftXcenter - 100) && lx < (leftXcenter + 100);
    bool validLY = ly > (leftYcenter - 100) && ly < (leftYcenter + 100);
    bool validRX = rx > (rightXcenter - 100) && rx < (rightXcenter + 100);
    bool validRY = ry > (rightYcenter - 100) && ry < (rightYcenter + 100);
    if(validLX && validLY && validRX && validRY)
    {
      i++;
      //nothing to do here!
    }
    else i = 0;
    delay(20);
  }
  leftXcenter = lx;
  leftYcenter = ly;
  rightXcenter = rx;
  rightYcenter = ry;
  multiplierLX = (double)127 / (double)lx;
  multiplierLY = (double)127 / (double)ly;
  multiplierRX = (double)127 / (double)rx;
  multiplierRY = (double)127 / (double)ry;
}

while (digitalRead(BOUTON2)) ;
while (digitalRead(BOUTON3)) ;
while (digitalRead(BOUTON4)) ;
while (digitalRead(BOUTON5)) ;
while (digitalRead(BOUTON6)) ;
while (digitalRead(BOUTON7)) ;
while (digitalRead(BOUTON8)) ;
while (digitalRead(BOUTON9)) ;
while (digitalRead(BOUTON10)) ;
while (digitalRead(BOUTON11)) ;
while (digitalRead(BOUTON12)) ;
while (digitalRead(BOUTON13)) ;

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