The code

Now, my build utilizes a library that makes the Arduino appear as a joystick, but beware AND THIS IS IMPORTANT! You absolutely NEED to have a circuitboard, Arduino or a PJRC Teensy, that has the atmega32u4 microcontroller in it, because atmega32u4 has native USB support. The information is easy enough to find on the manufacturers website. The library can be found here: https://github.com/MHeironimus/ArduinoJoystickLibrary However, the Teensy does NOT need the library.Why did I decide to use this library instead of using the Keyboard method in bobradars guide? Well, with this library you can use analog inputs and it doesn't spam numbers into any chat window or notepad or whatever if you happen to "be in gear" and alt+tab.The program used to write the code and upload it into the circuitboard of your choice can be downloaded from arduino.cc and it works with both the Teensy and Arduino boards. The library has to be installed to the arduinos library folder, the default is C:\Program Files (x86)\Arduino\librariesThe code below has comments and edits dependent on if you're using Teensy or not. Teensy code comes from Fleethammer.On to the code itself:#include "Joystick.h" //This is NOT required if using Teensy.int gearR = 0; // Reverse gear set to pin 0int gear1 = 1; //All pin numbers are to personal preference and whatever suits the build bestint gear2 = 2;int gear3 = 3;int gear4 = 4;int gear5 = 5;int gear6 = 6;int gear7 = 7;void setup() {pinMode(gearR, OUTPUT); // Set the gear as an inputdigitalWrite(gearR, HIGH); //Set the pin to HIGH or +5 VoltspinMode(gear1, OUTPUT);digitalWrite(gear1, HIGH);pinMode(gear2, OUTPUT);digitalWrite(gear2, HIGH);pinMode(gear3, OUTPUT);digitalWrite(gear3, HIGH);pinMode(gear4, OUTPUT);digitalWrite(gear4, HIGH);pinMode(gear5, OUTPUT);digitalWrite(gear5, HIGH);pinMode(gear6, OUTPUT);digitalWrite(gear6, HIGH);pinMode(gear7, OUTPUT);digitalWrite(gear7, HIGH);pinMode(A3, INPUT);pinMode(A0, INPUT);pinMode(8, OUTPUT);pinMode(10, OUTPUT);pinMode(14, OUTPUT);pinMode(16, OUTPUT);digitalWrite(8, HIGH);digitalWrite(10, HIGH);digitalWrite(14, HIGH); //These are required if your chipsetdigitalWrite(16, HIGH); //Doesn't have a +5V output pinJoystick.begin(); //Not needed with Teensyvoid loop() {if (digitalRead(gearR) == 0) // gear engaged (the '0' means the pin has been shorted to the ground, causing a drop in voltage on that pin)Joystick.setButton(0, 1); //Button number 0 is set to 1 or active state, Arduino//Joystick.button(0, 1); //Button number 0 is set to 1 or active state, Teensyif (digitalRead(gearR) == 1) //gear disengaged (the '1' means the pin is no longer shorted to the ground, which increases voltage on that pin)Joystick.setButton(0, 0); //tells the PC to let go of the key (otherwise, it would continue to hold it forever, even after another gear is selected)//Joystick.button(0, 0); //Button number 0 is set to 0 or inactive state, Teensyif (digitalRead(gear1) == 0)Joystick.setButton(1, 1);if (digitalRead(gear1) == 1) //gear disengagedJoystick.setButton(1, 0);if (digitalRead(gear2) == 0)Joystick.setButton(2, 1);if (digitalRead(gear2) == 1) //gear disengagedJoystick.setButton(2, 0);if (digitalRead(gear3) == 0)Joystick.setButton(3, 1);if (digitalRead(gear3) == 1) //gear disengagedJoystick.setButton(3, 0);if (digitalRead(gear4) == 0)Joystick.setButton(4, 1);if (digitalRead(gear4) == 1) //gear disengagedJoystick.setButton(4, 0);if (digitalRead(gear5) == 0)Joystick.setButton(5, 1);if (digitalRead(gear5) == 1) //gear disengagedJoystick.setButton(5, 0);if (digitalRead(gear6) == 0)Joystick.setButton(6, 1);if (digitalRead(gear6) == 1) //gear disengagedJoystick.setButton(6, 0);if (digitalRead(gear7) == 0)Joystick.setButton(7, 1);if (digitalRead(gear7) == 1) //gear disengagedJoystick.setButton(7, 0);// if (digitalRead(handBrake) == 0) //handbrake engaged //Use these if you have a digital handbrake// {// Joystick.setButton(8, 1);// }/*if (digitalRead(handBrake) == 1) //handbrake disengaged //Use these if you have a digital handbrakeJoystick.setButton(8, 0);}*/if (digitalRead(10)==0) //This checks the state of the handbrake mode switch, this is analog //mode//Serial.print("Handbrake raw: "); //These three lines//Serial.print(analogRead(A0)); //are used//Serial.print("\t"); //for debuggingif (analogRead(A0)>=1019)Joystick.setThrottle(0);//Joystick.X(0)); //Teensy analog axis Xif (analogRead(A0)<1019)int HBval = (-2.125*analogRead(A0))+2150; //This is unique to your build and you'll have to calculate it yourselfif (HBval < 0) HBval = 0;if (HBval > 255) HBval = 255;Joystick.setThrottle(HBval);//Joystick.X(analogRead(A0)); //Teensy analog axis X// Serial.print("Handbrake: "); //Debug//Serial.println(HBval); //linesif (digitalRead(8)==0)//This checks the state of the handbrake mode switch, this is digital modeif (analogRead(A0)>=1019)Joystick.setThrottle(0);Joystick.setButton(8, 0);if (analogRead(A0)<900)Joystick.setButton(8, 1);if (analogRead(A3)>=1019)Joystick.setRudder(0);//Joystick.Y(analogRead(A0)); //Teensy analog axis Yif (analogRead(A3)<1019)//Serial.print("Clutch raw: ");// Serial.print(analogRead(A3));// Serial.print("\t");int Cval = -0.3706395349*analogRead(A3)+344.3386628; //This is unique to your build and you'll have to calculate it yourself//Serial.print("Clutch: ");if (Cval < 0) Cval = 0;if (Cval > 255) Cval = 255;//Serial.println(Cval);Joystick.setRudder(Cval);//Joystick.Y(analogRead(A0)); //Teensy analog axis YNow, about the things you have to calculate yourself. When you have the build done, you have to set the limits of your analogue axis. You do that by removing the commented sections that have Serial.print in them. Then you open up the serial monitor in the arduino and see what data is printed. tha different axis go from 0 to 255, and the formula is as follows:y = k*x+b, where y is the axis value, k is the multiplier assigned to x which is the analogue input that varies from 0 to 1023 and b is the offset. So in this case the angle where the handbrake is not in use has 1019 coming in in the input (x), so we multiply it by -1.1643835616438356164383561643836(k, doesn't need to be this accurate) and add 1185.50684931506849315068493 which should give us 0 as y value or HBval, meaning the handbrake is off. When the lever is pulled, the input goes smaller, while the offset stays the same, so output goes higher.Teensy has it a bit easier, since axis values on Teensy go from 0 to 1023 so you can use the analog input as is and no calculations need to be made.