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
}