Emulates the pedals as a joystick over USB.
#include <Joystick.h>
const int Pin_Gas = A2;
const int Pin_Brake = A1;
const int Pin_Clutch = A0;
Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
0,
0,
false, false,
false, false, false, false, false, false);
const int ADC_Max = 1023;
const bool AlwaysSend = false;
void setup() {
Joystick.begin(false);
Joystick.setZAxisRange(0, ADC_Max);
Joystick.setRxAxisRange(0, ADC_Max);
Joystick.setRyAxisRange(0, ADC_Max);
updateJoystick();
}
void loop() {
updateJoystick();
}
}
void updateJoystick() {
int gasPedal = pedals.
getPosition(SimRacing::Gas, 0, ADC_Max);
Joystick.setRyAxis(gasPedal);
}
if (pedals.
hasPedal(SimRacing::Brake)) {
int brakePedal = pedals.
getPosition(SimRacing::Brake, 0, ADC_Max);
Joystick.setRxAxis(brakePedal);
}
if (pedals.
hasPedal(SimRacing::Clutch)) {
int clutchPedal = pedals.
getPosition(SimRacing::Clutch, 0, ADC_Max);
Joystick.setZAxis(clutchPedal);
}
Joystick.sendState();
}
Header file for the Sim Racing Library.
Interface with the Logitech pedals (Gas, Brake, and Clutch)
bool hasPedal(PedalID pedal) const
Checks if a given pedal is present in the class.
bool positionChanged() const
Checks whether the current pedal positions have changed since the last update.
virtual bool update()
Perform a poll of the hardware to refresh the class state.
virtual void begin()
Initialize the hardware (if necessary)
long getPosition(PedalID pedal, long rMin=0, long rMax=100) const
Retrieves the buffered position for the pedal, rescaled to a nominal range using the calibration valu...