Skip to content

Instantly share code, notes, and snippets.

@RazerMoon
Created June 26, 2021 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RazerMoon/dd1112c660545814fee68667d8427c8a to your computer and use it in GitHub Desktop.
Save RazerMoon/dd1112c660545814fee68667d8427c8a to your computer and use it in GitHub Desktop.
FSX custom throttle
#include "Joystick.h"
// https://github.com/MHeironimus/ArduinoJoystickLibrary
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_GAMEPAD, 0, 0, // first no. is how many button there are
false , false, false, false, false, false,
true, true, false, false, false);
int throttle = A0;
int rudder = A1;
int throttleValue = 0;
int rudderValue = 0;
int prevrudValue = 0;
int prevthroValue = 0;
int sens = 5;
// init joystick libary
void setup() {
Joystick.begin();
}
void loop() {
throttleValue = analogRead(throttle);
rudderValue = analogRead(rudder);
if (abs(throttleValue - prevthroValue) > sens) {
Joystick.setThrottle(throttleValue);
prevthroValue = throttleValue;
}
if (abs(rudderValue - prevrudValue) > sens) {
Joystick.setRudder(rudderValue);
prevrudValue = rudderValue;
}
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment