Hi again,
I am having a problem with my button box for sim racing and flight/space sim project
:
I tried to ask to gemini to create code, thats work, buuut, on my 5 pin axis stick, only one work, (x) the others are not working, tested my wiring, and serial monitor doesn't reveal any communication problems, so, maybe a code problem created by Gemini ? someone can tell to me what is wrong ?
#include <Joystick.h>
// Définition des broches pour les boutons momentanés
const int boutonPins[] = {2, 3, 4, 5, 6, 7};
// Définition des broches pour les axes du joystick principal
const int joystickXPin = A0;
const int joystickYPin = A1;
// Définition des broches pour les axes supplémentaires
const int autreAxe1Pin = A2;
const int autreAxe2Pin = A3;
// Définition des broches pour les interrupteurs toggle 1 position
const int togglePins[] = {8, 9};
// Définition des broches pour les interrupteurs momentanés On-Off-On
const int momentaryOnOffOnPins[][2] = {{10, 11}, {12, 13}};
// Création de l'objet Joystick
Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_GAMEPAD,
12, // Nombre de boutons (6 momentanés + 2 toggles + 2 * 2 pour les On-Off-On)
4, // Nombre d'axes (Joystick X, Joystick Y, Autre Axe 1, Autre Axe 2)
false, // Utiliser ou non les données de point de vue (hat switches)
false, // Utiliser ou non les boutons de direction (d-pad)
false // Auto-envoyer les mises à jour
);
void setup() {
// Initialisation des boutons momentanés en entrée avec pull-up interne
for (int pin : boutonPins) {
pinMode(pin, INPUT_PULLUP);
}
// Initialisation des interrupteurs toggle en entrée avec pull-up interne
for (int pin : togglePins) {
pinMode(pin, INPUT_PULLUP);
}
// Initialisation des interrupteurs momentanés On-Off-On en entrée avec pull-up interne
for (int i = 0; i < 2; ++i) {
pinMode(momentaryOnOffOnPins[i][0], INPUT_PULLUP);
pinMode(momentaryOnOffOnPins[i][1], INPUT_PULLUP);
}
// Initialisation de la librairie Joystick
Joystick.begin();
}
void loop() {
// Lecture et mise à jour des boutons momentanés
for (int i = 0; i < 6; ++i) {
Joystick.setButton(i + 1, digitalRead(boutonPins[i]) == LOW);
}
// Lecture et mise à jour des interrupteurs toggle
for (int i = 0; i < 2; ++i) {
Joystick.setButton(i + 7, digitalRead(togglePins[i]) == LOW);
}
// Lecture et mise à jour des interrupteurs momentanés On-Off-On
for (int i = 0; i < 2; ++i) {
Joystick.setButton(i + 9, digitalRead(momentaryOnOffOnPins[i][0]) == LOW); // Première position ON
Joystick.setButton(i + 10, digitalRead(momentaryOnOffOnPins[i][1]) == LOW); // Seconde position ON
}
// Lecture des valeurs des axes analogiques et mise à jour du joystick
Joystick.setXAxis(analogRead(joystickXPin));
Joystick.setYAxis(analogRead(joystickYPin));
Joystick.setZAxis(analogRead(autreAxe1Pin)); // Utilisation de l'axe Z pour l'autre axe 1
Joystick.setRAxis(analogRead(autreAxe2Pin)); // Utilisation de l'axe R pour l'autre axe 2
// Envoi de l'état du joystick
Joystick.sendState();
delay(5);
}