Welcome to Cockpitbuilders.com. Please login or sign up.

May 09, 2024, 12:07:11 PM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
543 Guests, 0 Users
Members
Stats
  • Total Posts: 59,641
  • Total Topics: 7,853
  • Online today: 588
  • Online ever: 831
  • (May 03, 2024, 12:39:25 PM)
Users Online
Users: 0
Guests: 543
Total: 543

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Teensy as Joystick

Started by kurt-olsson, April 16, 2019, 08:49:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kurt-olsson

Simplest code ever.

I plug my Teensy in, it works, i calibrate my joystick in X-Plane 11. Once i click Done and return to flight, the joystick stops working after about 2 seconds.

I disconnect it, redo the calibration and it works for... 2 sec.

I am out of ideas, any help is really appreciated.

Teensy 3.2, USB Type: Flight Sim Controls + Joystick.

Code:


float roll = 0;
float pitch = 0;


void setup() {
  pinMode(23, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
   

  analogReadResolution(16);


   
}

void loop() {
   
  //FlightSim.update();

  int rollValue1Avg = 0;
  for(int i = 0; i < 20;i++) {
    rollValue1Avg += analogRead(23);
  }
  rollValue1Avg = rollValue1Avg / 20;

  int pitchValue1Avg = 0;
  for(int i = 0; i < 20;i++) {
    pitchValue1Avg += analogRead(22);
  }
  pitchValue1Avg = pitchValue1Avg / 20;

  roll = mapfloat(rollValue1Avg,12000,2000,0,1023);
  pitch = mapfloat(pitchValue1Avg,9200,15700,0,1023);


 
  Joystick.X(roll);
  Joystick.Y(pitch);
  delay(50);
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

kurt-olsson

Hm... think i solved it, use only keybourd / mouse / joystick in USB Type without Flight Sim Control and then it works.

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate