Cockpitbuilders.com
Arduino Projects => Sketches - => Topic started by: kurt-olsson on February 04, 2019, 12:34:38 PM
This is one side of my Flight Control Panel. I Hate this code, i hate the Commands.
If anyone has a better way of doing this let me know!
const int PIN_KORRY_PUSH_TO_TEST = 16;
const int PIN_KORRY_YAW_DAMPER = 17;
const int PIN_KORRY_AUTO_SLAT_FAIL = 20;
const int PIN_KORRY_FEEL_DIFF_PRESS = 10;
const int PIN_KORRY_MACH_TRIM_FAIL = 9;
const int PIN_KORRY_SPEED_TRIM_FAIL = 6;
const int PIN_SWITCH_YAW_DAMPER = 13;
const int PIN_SWITCH_FLIGHT_CONTROL_A_STBY_RUD = 18;
const int PIN_SWITCH_FLIGHT_CONTROL_A_ON = 19;
const int PIN_SWITCH_FLIGHT_CONTROL_B_STBY_RUD = 14;
const int PIN_SWITCH_FLIGHT_CONTROL_B_ON = 15;
const int PIN_RELAY_YAW_DAMPER = 21;
FlightSimFloat xPlane_readonly_flt_ctr_A_cover_pos;
FlightSimFloat xPlane_readonly_flt_ctr_B_cover_pos;
FlightSimCommand Command_flt_ctr_A_cover;
FlightSimCommand Command_flt_ctr_B_cover;
FlightSimCommand Command_flt_ctr_A_up;
FlightSimCommand Command_flt_ctr_A_dn;
FlightSimFloat xPlane_flt_ctr_A_pos;
FlightSimCommand Command_flt_ctr_B_up;
FlightSimCommand Command_flt_ctr_B_dn;
FlightSimFloat xPlane_flt_ctr_B_pos;
void setup() {
FlightSim.update();
//Serial.begin(9600);
pinMode(PIN_KORRY_PUSH_TO_TEST, OUTPUT);
pinMode(PIN_KORRY_YAW_DAMPER, OUTPUT);
pinMode(PIN_KORRY_AUTO_SLAT_FAIL, OUTPUT);
pinMode(PIN_KORRY_FEEL_DIFF_PRESS, OUTPUT);
pinMode(PIN_KORRY_MACH_TRIM_FAIL, OUTPUT);
pinMode(PIN_KORRY_SPEED_TRIM_FAIL, OUTPUT);
pinMode(PIN_SWITCH_YAW_DAMPER,INPUT_PULLUP);
pinMode(PIN_SWITCH_FLIGHT_CONTROL_A_STBY_RUD,INPUT_PULLUP);
pinMode(PIN_SWITCH_FLIGHT_CONTROL_A_ON,INPUT_PULLUP);
pinMode(PIN_SWITCH_FLIGHT_CONTROL_B_ON,INPUT_PULLUP);
pinMode(PIN_SWITCH_FLIGHT_CONTROL_B_STBY_RUD,INPUT_PULLUP);
pinMode(PIN_RELAY_YAW_DAMPER,OUTPUT);
xPlane_readonly_flt_ctr_A_cover_pos = XPlaneRef("laminar/B738/switches/flt_ctr_A_cover_pos");
xPlane_readonly_flt_ctr_B_cover_pos = XPlaneRef("laminar/B738/switches/flt_ctr_B_cover_pos");
Command_flt_ctr_A_cover = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_A_cover");
Command_flt_ctr_B_cover = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_B_cover");
Command_flt_ctr_A_up = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_A_up");
Command_flt_ctr_A_dn = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_A_dn");
xPlane_flt_ctr_A_pos = XPlaneRef("laminar/B738/switches/flt_ctr_A_pos");
Command_flt_ctr_B_up = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_B_up");
Command_flt_ctr_B_dn = XPlaneRef("laminar/B738/toggle_switch/flt_ctr_B_dn");
xPlane_flt_ctr_B_pos = XPlaneRef("laminar/B738/switches/flt_ctr_B_pos");
}
void loop() {
FlightSim.update();
// put your main code here, to run repeatedly:
analogWrite(PIN_KORRY_PUSH_TO_TEST,255);
analogWrite(PIN_KORRY_YAW_DAMPER,255);
analogWrite(PIN_KORRY_AUTO_SLAT_FAIL,255);
analogWrite(PIN_KORRY_FEEL_DIFF_PRESS,255);
analogWrite(PIN_KORRY_MACH_TRIM_FAIL,255);
analogWrite(PIN_KORRY_SPEED_TRIM_FAIL,255);
digitalWrite(PIN_RELAY_YAW_DAMPER,HIGH);
//THIS CODE IS JUST BS, MUST BE A BETTER WAY OF DOING THIS!
if (xPlane_readonly_flt_ctr_A_cover_pos == 0.0f) {
Command_flt_ctr_A_cover.once();
}
if (xPlane_readonly_flt_ctr_B_cover_pos == 0.0f) {
Command_flt_ctr_B_cover.once();
}
if (xPlane_readonly_flt_ctr_A_cover_pos == 1 && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_STBY_RUD) == LOW && xPlane_flt_ctr_A_pos != -1) {
Command_flt_ctr_A_up.once();
delay(200);
}
if (xPlane_readonly_flt_ctr_A_cover_pos == 1 && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_ON) == LOW && xPlane_flt_ctr_A_pos != 1) {
Command_flt_ctr_A_dn.once();
delay(200);
}
if (digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_STBY_RUD) == HIGH && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_ON) == HIGH) {
if (xPlane_flt_ctr_A_pos == -1)
Command_flt_ctr_A_dn.once();
if (xPlane_flt_ctr_A_pos == 1)
Command_flt_ctr_A_up.once();
delay(200);
}
if (xPlane_readonly_flt_ctr_B_cover_pos == 1 && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_STBY_RUD) == LOW && xPlane_flt_ctr_B_pos != -1) {
Command_flt_ctr_B_up.once();
delay(200);
}
if (xPlane_readonly_flt_ctr_B_cover_pos == 1 && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_ON) == LOW && xPlane_flt_ctr_B_pos != 1) {
Command_flt_ctr_B_dn.once();
delay(200);
}
if (digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_STBY_RUD) == HIGH && digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_ON) == HIGH) {
if (xPlane_flt_ctr_B_pos == -1)
Command_flt_ctr_B_dn.once();
if (xPlane_flt_ctr_B_pos == 1)
Command_flt_ctr_B_up.once();
delay(200);
}
//Serial.println(digitalRead(PIN_SWITCH_YAW_DAMPER));
//Serial.print(digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_STBY_RUD));
//Serial.print(digitalRead(PIN_SWITCH_FLIGHT_CONTROL_A_ON));
//Serial.print(digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_STBY_RUD));
//Serial.print(digitalRead(PIN_SWITCH_FLIGHT_CONTROL_B_ON));
delay(20);
}