Skip to content

01. How to use the library (Basic)

Jorg Neves Bliesener edited this page Jan 13, 2019 · 5 revisions

Installing the library

The FlightSimSwitches library is available through the Arduino Library manager.

Just install it and include it in your sketch. That should automatically put a

#include <FlightSimSwitches.h>

in your code.

Simple example

The most basic use case of the library may look like in the following short code. This is a simplified version of the Demo_Cessna172 sketch in the library's example folder:

#include <FlightSimSwitches.h>

FlightSimSwitches switches;
FlightSimOnOffCommandSwitch taxiLightSwitch(2);
FlightSimOnOffCommandSwitch landingLightSwitch(5);

void setup() {
  Serial.begin(9600);

  taxiLightSwitch.setOnOffCommands(
    XPlaneRef("sim/lights/taxi_lights_on"),
    XPlaneRef("sim/lights/taxi_lights_off"));

  landingLightSwitch.setOnOffCommands(
    XPlaneRef("sim/lights/landing_lights_on"),
    XPlaneRef("sim/lights/landing_lights_off"));

  switches.setDebug(DEBUG_SWITCHES);
  switches.begin();
}

void loop() {
  FlightSim.update();
  switches.loop();
}

This would create a FlightSimSwitches object with two direct inputs on pins 2 and 5, as well as two switches that are controlled through ON and OFF commands. The first switch would be called taxiLightSwitch and would use pin number 2. The second switch called landingLightSwitch would be associated with pin number 5.

In the setup() function, the commands associated with the switch actions are defined. Furthermore, debug output is enabled and the begin() function is called for the FlightSimSwitches. Calling begin() is very important. Without it, your sketches will not work correctly!

Connect the switch that will control X-Plane's taxi lights between Teensy pin 2 and GND. The landing light switch goes between pin 5 and GND.

Set your Arduino IDE to use the Teensy and set the USB type to include "Flight Sim Controls". Compile the sketch above and run it.

Start X-Plane (with the Teensy plugin installed, see https://github.com/jbliesener/X-Plane_Plugin) and load a plane. The basic Cessna 172 does the job. Enjoy your switches controlling the Cessna and take a look from the outside to see how they work.