Skip to content

Instantly share code, notes, and snippets.

@RazerMoon
Created March 2, 2021 13:41
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/b746316d1f8e5df5f57d7562fac6347a to your computer and use it in GitHub Desktop.
Save RazerMoon/b746316d1f8e5df5f57d7562fac6347a to your computer and use it in GitHub Desktop.
#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