Just a quick update from my end, I've updated the sketch and now have the Mode and View buttons configured. I still haven't looked into getting the actual button LEDs to light up but switches work in control panel. I've just wired up the four digital input wires for the shifter and will be trying to get that working next. The sketch is based on baritonomarchetto sketch and the example included with the Joystick library.
/* ArcadeHID - steering wheel handling example
* gamepad emulation
*
* by Barito, 2021
* Rev-3 - Steering, Accelerator, Brake + 2 Buttons
*/
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_MULTI_AXIS,
2, 0, // Button Count, Hat Switch Count
false, false, false, // X, Y, Z Axis
false, false, false, //Rx, Ry, Rz
false, false, //rudder, throttle
true, true, true); //accelerator, brake, steering
const int steerPin = A0;
const int brakePin = A1;
const int accelPin = A2;
int steerValue;
int brakeValue;
int accelValue;
void setup() {
//Steering Options - X Axis or Steering
//Joystick.setXAxisRange(0, 1023); //Steering Wheel - Joystick.setXAxisRange(min, max);
Joystick.setSteeringRange(0, 960);
//Brake Options - Y Axis or Brake
//Joystick.setYAxisRange(0, 1023); //Brake Pedal - Joystick.setYAxisRange(min, max);
Joystick.setBrakeRange(366, 767);
Serial.begin(9600); // Testing analog input
//Accelerator Options - Z Axis or Acceleratro
//Joystick.setZAxisRange(0, 1023); //Accel Pedal - Joystick.setZAxisRange(min, max);
Joystick.setAcceleratorRange(490, 915);
//Default Buttons - WMMT (Mode (Red Button) and View (Green Button))
//Initialise button pins
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
//Start Joystick
Joystick.begin();
}
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 7;
// Last state of the button
int lastButtonState[2] = {0,0};
void loop() {
BrakePedal();
SteerWheel();
AccelPedal();
ReadButtons();
}
void SteerWheel(){
steerValue = analogRead(steerPin);
//Joystick.setXAxis(steerValue);
Joystick.setSteering(steerValue);
delay(1);
}
void BrakePedal(){
brakeValue = analogRead(brakePin);
//Joystick.setYAxis(brakeValue);
Joystick.setBrake(brakeValue);
Serial.println(brakeValue); // Testing analog input
delay(1);
}
void AccelPedal(){
accelValue = analogRead(accelPin);
//Joystick.setZAxis(accelValue);
Joystick.setAccelerator(accelValue);
delay(1);
}
void ReadButtons(){
// Read digital pin values
for (int index = 0; index < 2; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}