Help with code of simracing pedals

i have this code for pedals of simracing and the cluth not works and i dont know

#include "Joystick.h" // GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
#include "HX711.h" // GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.

#define DOUT 3
#define CLK 2
#define POT_ACCEL_PIN A0 // Pin para el potenciómetro del acelerador
#define POT_CLUTCH_PIN A1 // Pin para el potenciómetro del embrague

HX711 scale;
float calibration_factor = -1500; // Este valor controla la sensibilidad del pedal

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 0, 0,
false, false, false, false, false, false,
true, true, true, true, false); // Habilitamos los ejes: Brake, Throttle, Z Rotation (para embrague)

int brake = 0;
int lastBrakeValue = 0;
int accel = 0;
int lastAccelValue = 0;
int clutch = 0;
int lastClutchValue = 0;

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

scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); // Reiniciar la báscula a 0
scale.set_scale(calibration_factor);

Joystick.setBrakeRange(0, 1023); // Rango para el freno
Joystick.setThrottleRange(0, 1023); // Rango para el acelerador
Joystick.setRzAxisRange(0, 1023); // Rango para el embrague (como Z Rotation)
Joystick.begin();
}

void loop() {
// Leer valor de la báscula para el freno
brake = scale.get_units();
brake = constrain(brake, 0, 1023);

// Leer valor del potenciómetro para el acelerador
accel = analogRead(POT_ACCEL_PIN);
accel = map(accel, 0, 1023, 0, 1023); // Ajustar el valor al rango

// Leer valor del potenciómetro para el embrague
clutch = analogRead(POT_CLUTCH_PIN);
clutch = map(clutch, 0, 1023, 0, 1023); // Ajustar el valor al rango

// Imprimir valores para depuración
Serial.print("Clutch Value: ");
Serial.println(clutch);

// Actualizar el freno si ha cambiado
if (lastBrakeValue != brake) {
Joystick.setBrake(brake);
lastBrakeValue = brake;
}

// Actualizar el acelerador si ha cambiado
if (lastAccelValue != accel) {
Joystick.setThrottle(accel);
lastAccelValue = accel;
}

// Actualizar el embrague si ha cambiado
if (lastClutchValue != clutch) {
Joystick.setRzAxis(clutch); // Usar Z Rotation para el embrague
lastClutchValue = clutch;
}

delay(10); // Pequeño retraso para evitar sobrecargar el procesador
}

Are you using the right Arduino? From the library:

The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).

Did you clone the libraries?

Reformat your code and wrap it in < CODE > marks (``` and ```)

This is the trouble with copy/paste and know learning.

si la estoy usando con un pro micro pero me funciona todo menos el el embrague

y si clone las bibliotecas , me funciona todo menos uno de los potenciometros analogicos

¿Es la perilla analógica el embrague? Si el acelerador funciona, supongo que el problema es el cableado.

Is the analog knob the clutch? If the accelerator works, I would guess the problem is wiring.

si son las dos analogicas menos el freno que es una celula de carga y el cableado esta correcto

eso me sale en windows no se porque me dice que es otro acelerador y sale en un cuadrado la cuestion es que no funciona si me pudieses ayudar te lo agradeceria mucho

Try these things: (1) Change the clutch code from A1 to A2 and change the wire from A1 to A2 and test. If that does not show the problem, and you know A0 works for the accelerator, (2) change clutch and accelerator in the code and (3) in the wiring.

Pruebe dos cosas: (1) Cambie el código del embrague de A1 a A2 y cambie el cable de A1 a A2 y pruebe. Si eso no muestra el problema, y sabe que A0 funciona para el acelerador, (2) cambie el embrague y el acelerador en el código y (3) en el cableado.

I have been helping. Maybe I am not fast enough for you and you should find someone faster.

He estado ayudando. Tal vez no soy lo suficientemente rápido para ti y deberías encontrar a alguien más rápido.

Please use English in the main forum or move your topic to the Spanish section.

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