03.05. FlightSimPushbutton
Jorg Neves Bliesener edited this page Jan 13, 2019
·
2 revisions
This object is similar to the FlightSimOnOffCommandSwitch object, but it is designed for Pushbuttons that use X-Plane's "command begin" and "command end" functions. It uses a single command and, whenever the switch is closed, it sends "command begin". When the switch is opened, the object sends "command end" to X-Plane.
As there's only a single command, it can be assigned directly to the switch
object. As with FlightSimOnOffCommandSwitch,
the pin number can be specified on declaration or during setup()
.
Furthermore, there polarity of the switch can be set with setInverted()
or on
initialization:
#include <FlightSimSwitches.h>
// always declare FlightSimSwitches first
FlightSimSwitches switches;
// Pin number specified in object declaration
FlightSimPushbutton pb1(2); // Pushbutton between pin 2 and GND
// Pin Number specified in setup()
FlightSimPushbutton pb2;
// Inverted logic: Send END when button closes and BEGIN when
// button opens
FlightSimPushbutton pb3(4, true); // normally closed (N/C) pushbutton
// between pin 4 and GND
// Set parameters in setup()
FlightSimPushbutton pb4;
void setup() {
delay(1000);
// set pushbutton 1 command
pb1 = XPlaneRef("command/1");
// set pushbutton 2 pin and commands
pb2.setPosition(3);
pb2 = XPlaneRef("command/2");
// set pushbutton 3 command (inverted)
pb3 = XPlaneRef("command/3");
// set pushbutton 4 pin and commands
pb4.setPosition(5);
pb4.setInverted(true);
pb4 = XPlaneRef("command/4");
switches.setDebug(DEBUG_SWITCHES);
switches.begin();
}
void loop() {
FlightSim.update();
switches.loop();
}