-
Notifications
You must be signed in to change notification settings - Fork 7
01. How to use the library (Basic)
The most basic use case of the library may look like this:
#include <FlightSimSwitches.h>
FlightSimSwitches switches(2,SWITCH_PINS(2,5));
FlightSimOnOffCommandSwitch taxiLightSwitch(0);
FlightSimOnOffCommandSwitch landingLightSwitch(1);
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 the first of the two input pins (pin 2). The second switch called
landingLightSwitch
would be associated with the second input pin (pin 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.