Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steveatinfincia/c75912fad911732f0debbfb1fec58a60 to your computer and use it in GitHub Desktop.
Save steveatinfincia/c75912fad911732f0debbfb1fec58a60 to your computer and use it in GitHub Desktop.
/*
* Author: Jurgen "PlantCorn" Schull <j.schull@plantcorn.com>
* I originally created this for a mode 2 controller (Turnigy 9xr Pro) as most of the other
* solutions available to me simply did not work or were too much of a pain.
* things such as smartpropro plus did not work at all for me, and out of frustration I
* created this. I calibrated the controller, and within minutes i was able to use my
* favorite sims, I hope this also works for you.
* Be sure to upload to your teensy in serial+keyboard+mouse+joych mode, 72mhz optimized
* i used a Teensy 3.1 with ppm input on pin 10 and ppm ground to GND
*/
#include <PulsePosition.h>
PulsePositionInput joyIn;
void setup() {
Joystick.useManualSend(true);
joyIn.begin(10);
//Serial.begin(115200);
}
void loop() {
int num;
num = joyIn.available();
if (num > 0) {
//Serial.print("Channels received: ");
//Serial.print(num);
//Serial.println("");
// read 6 analog inputs and use them for the joych axis
int ch1_raw = joyIn.read(1);
int ch1_constrained = constrain(ch1_raw, 1000, 2000);
int ch1 = map(ch1_constrained, 1000, 2000, 0, 1024 * 64);
int ch2_raw = joyIn.read(2);
int ch2_constrained = constrain(ch2_raw, 1000, 2000);
int ch2 = map(ch2_constrained, 1000, 2000, 0, 1024 * 64);
int ch3_raw = joyIn.read(3);
int ch3_constrained = constrain(ch3_raw, 1000, 2000);
int ch3 = map(ch3_constrained, 1000, 2000, 0, 1024 * 64);
int ch4_raw = joyIn.read(4);
int ch4_constrained = constrain(ch4_raw, 1000, 2000);
int ch4 = map(ch4_constrained, 1000, 2000, 0, 1024 * 64);
int ch5_raw = joyIn.read(5);
int ch5_constrained = constrain(ch5_raw, 1000, 2000);
int ch5 = map(ch5_constrained, 1000, 2000, 0, 1024 * 64);
int ch6_raw = joyIn.read(6);
int ch6_constrained = constrain(ch6_raw, 1000, 2000);
int ch6 = map(ch6_constrained, 1000, 2000, 0, 1024 * 64);
int ch7_raw = joyIn.read(7);
int ch7_constrained = constrain(ch7_raw, 1000, 2000);
int ch7 = map(ch7_constrained, 1000, 2000, 0, 1024 * 64);
int ch8_raw = joyIn.read(8);
int ch8_constrained = constrain(ch8_raw, 1000, 2000);
int ch8 = map(ch8_constrained, 1000, 2000, 0, 1024 * 64);
//Serial.print(" <ch1:");
//Serial.print(ch1_raw);
//Serial.print(":");
//Serial.print(ch1);
//Serial.print(">");
//Serial.print(" <ch2:");
//Serial.print(ch2_raw);
//Serial.print(":");
//Serial.print(ch2);
//Serial.print(">");
//Serial.print(" <ch3:");
//Serial.print(ch3_raw);
//Serial.print(":");
//Serial.print(ch3);
//Serial.print(">");
//Serial.print(" <ch4:");
//Serial.print(ch4_raw);
//Serial.print(":");
//Serial.print(ch4);
//Serial.print(">");
//Serial.print(" <ch5:");
//Serial.print(ch5_raw);
//Serial.print(":");
//Serial.print(ch5);
//Serial.print(">");
//Serial.print(" <ch6:");
//Serial.print(ch6_raw);
//Serial.print(":");
//Serial.print(ch6);
//Serial.print(">");
//Serial.print(" <ch7: ");
//Serial.print(ch7_raw);
//Serial.print(":");
//Serial.print(ch7);
//Serial.print(">");
//Serial.print(" <ch8: ");
//Serial.print(ch8_raw);
//Serial.print(":");
//Serial.print(ch8);
//Serial.print("> ");
Joystick.X(ch1);//Pitch
Joystick.Y(ch2);//Roll
Joystick.Z(ch3);//Throttle
Joystick.Xrotate(ch4);
Joystick.Yrotate(ch5);
Joystick.Zrotate(ch6);
Joystick.slider(1, ch7);
Joystick.slider(2, ch8);
}
Joystick.send_now();
delay(5);
//Serial.println(" \r\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment