Skip to content

Instantly share code, notes, and snippets.

@joegaffey
Last active July 10, 2023 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegaffey/15bc76fa8b89fa941570b381fa884ad4 to your computer and use it in GitHub Desktop.
Save joegaffey/15bc76fa8b89fa941570b381fa884ad4 to your computer and use it in GitHub Desktop.
Basic Arduino script to convert an RC controller/receiver to a joystick.
#include <Joystick.h>
#define ThrottlePin 2
#define SteeringPin 3
int ThrottleValue;
int SteeringValue;
Joystick_ Joystick;
void setup() {
pinMode(ThrottlePin, INPUT);
pinMode(SteeringPin, INPUT);
Joystick.begin();
Joystick.setXAxisRange(1900, 1050);
Joystick.setYAxisRange(1050, 1900);
}
void loop() {
ThrottleValue = pulseIn(ThrottlePin, HIGH);
SteeringValue = pulseIn(SteeringPin, HIGH);
Joystick.setXAxis(SteeringValue);
Joystick.setYAxis(ThrottleValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment