// Used on "Teensy++2", "16MHz", with "Flight Sim Controls", "US English". // Test code to illustrate the issue with continuous X-Plane updates. // Extracts from a larger code to illustrate issue. // The heading only needs to be receved from X-Plane when the LHLongPush reches // its time out after 200 program cycles and courseBug is reset to heading. // How do I stop getting heading updates all the time? I only need one update // at the time of resetting headingBug to heading? // Run X-Plane 11 and use Plugins / TeensyControls to see code communictions with X-Plane. int LHButton = 0; int LHLongPush = 0; const int loopLed = 6; FlightSimInteger courseBug; FlightSimFloat heading; void setup() { pinMode (18, INPUT_PULLUP); // LH Button input pull up. pinMode (loopLed, OUTPUT); // LoopLed changes state on every program cycle. courseBug = XPlaneRef("sim/cockpit2/radios/actuators/hsi_obs_deg_mag_pilot"); heading = XPlaneRef("sim/cockpit/gyros/psi_ind_degm3"); } void loop() { FlightSim.update(); LHButton = digitalRead(18); //Left Hand Control Knob Push. // LH Long Push sets Course Pointer to current heading. if (LHButton == LOW) { LHLongPush = LHLongPush + 1; } if (LHLongPush > 200) { courseBug = heading; // set courseBug to heading after 200 program cycles of continuous LHButton push. LHLongPush = 0; } if (LHButton == HIGH) { LHLongPush = 0; } // changes the state of the internal LED on each prog cycle. digitalWrite(loopLed, !digitalRead(loopLed)); delay (10); //sets button debounce time for all buttons pressed. }