Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bounce.h>
- FlightSimCommand master_bat_on;
- FlightSimCommand master_bat_off;
- FlightSimCommand master_alt_on;
- FlightSimCommand master_alt_off;
- FlightSimCommand avionics_master_on;
- FlightSimCommand avionics_master_off;
- FlightSimCommand fuel_pump_on;
- FlightSimCommand fuel_pump_off;
- FlightSimCommand carb_heat_on;
- FlightSimCommand carb_heat_off;
- FlightSimCommand pitot_heat_on;
- FlightSimCommand pitot_heat_off;
- FlightSimCommand landing_gear_up;
- FlightSimCommand landing_gear_down;
- FlightSimCommand lights_beacon_on;
- FlightSimCommand lights_beacon_off;
- FlightSimCommand lights_nav_on;
- FlightSimCommand lights_nav_off;
- FlightSimCommand lights_stobe_on;
- FlightSimCommand lights_strobe_off;
- FlightSimCommand lights_taxi_on;
- FlightSimCommand lights_taxi_off;
- FlightSimCommand lights_landing_on;
- FlightSimCommand lights_landing_off;
- FlightSimCommand flaps_up;
- FlightSimCommand flaps_down;
- FlightSimInteger fuel;
- FlightSimInteger stall;
- struct SWITCH{
- int pin;
- String label;
- Bounce bounce;
- boolean switchedOn;
- };
- const int NB_OF_SWITCHES = 14;
- SWITCH switches[] = {
- {2, "master bat", Bounce(2, 5), false}
- ,{3, "master alt", Bounce(3, 5), false}
- ,{4, "avionics master", Bounce(4, 5), false}
- ,{5, "fuel pump", Bounce(5, 5), false}
- ,{6, "carb heat", Bounce(6, 5), false}
- ,{7, "pitot heat", Bounce(7, 5), false}
- ,{8, "landing gear", Bounce(8, 5), false}
- ,{9, "lights beacon", Bounce(9, 5), false}
- ,{10, "lights nav", Bounce(10, 5), false}
- ,{11, "lights strobe", Bounce(11, 5), false}
- ,{12, "lights taxi", Bounce(12, 5), false}
- ,{13, "lights landing", Bounce(13, 5), false}
- ,{44, "flaps up", Bounce(44, 5), false}
- ,{45, "flaps down", Bounce(45, 5), false}
- };
- int fuelRedPin = 14;
- int stallRedPin = 15;
- void setup(){
- Serial.begin(38400);
- Serial.println("************");
- Serial.println("* new boot *");
- Serial.println("************");
- pinMode(2, INPUT);
- pinMode(3, INPUT);
- pinMode(4, INPUT);
- pinMode(5, INPUT);
- pinMode(6, INPUT);
- pinMode(7, INPUT);
- pinMode(8, INPUT);
- pinMode(9, INPUT);
- pinMode(10, INPUT);
- pinMode(11, INPUT);
- pinMode(12, INPUT);
- pinMode(13, INPUT);
- master_bat_on = XPlaneRef("sim/electrical/battery_1_on");
- master_bat_off = XPlaneRef("sim/electrical/battery_1_off");
- master_alt_on = XPlaneRef("sim/electrical/inverters_on");
- master_alt_off = XPlaneRef("sim/electrical/inverters_off");
- avionics_master_on = XPlaneRef("sim/systems/avionics_on");
- avionics_master_off = XPlaneRef("sim/systems/avionics_off");
- fuel_pump_on = XPlaneRef("sim/fuel/fuel_pump_1_on");
- fuel_pump_off = XPlaneRef("sim/fuel/fuel_pump_1_off");
- carb_heat_on = XPlaneRef("sim/engines/carb_heat_on");
- carb_heat_off = XPlaneRef("sim/engines/carb_heat_off");
- pitot_heat_on = XPlaneRef("sim/ice/pitot_heat_on");
- pitot_heat_off = XPlaneRef("sim/ice/pitot_heat_off");
- landing_gear_up = XPlaneRef("sim/flight_controls/landing_gear_up");
- landing_gear_down = XPlaneRef("sim/flight_controls/landing_gear_down");
- lights_beacon_on = XPlaneRef("sim/lights/beacon_lights_on");
- lights_beacon_off = XPlaneRef("sim/lights/beacon_lights_off");
- lights_nav_on = XPlaneRef("sim/lights/nav_lights_on");
- lights_nav_off = XPlaneRef("sim/lights/nav_lights_off");
- lights_stobe_on = XPlaneRef("sim/lights/strobe_lights_on");
- lights_strobe_off = XPlaneRef("sim/lights/strobe_lights_off");
- lights_taxi_on = XPlaneRef("sim/lights/taxi_lights_on");
- lights_taxi_off = XPlaneRef("sim/lights/taxi_lights_off");
- lights_landing_on = XPlaneRef("sim/lights/landing_lights_on");
- lights_landing_off = XPlaneRef("sim/lights/landing_lights_off") ;
- flaps_up = XPlaneRef("sim/flight_controls/flaps_up");
- flaps_down = XPlaneRef("sim/flight_controls/flaps_down");
- pinMode(fuelRedPin, OUTPUT);
- fuel = XPlaneRef("sim/cockpit2/annunciators/fuel_quantity");
- fuel.onChange(updateFuelLight);
- pinMode(stallRedPin, OUTPUT);
- stall = XPlaneRef("sim/cockpit2/annunciators/stall_warning");
- stall.onChange(updateStallLight);
- for(int i=0; i<NB_OF_SWITCHES; i++){
- if(digitalRead(switches[i].pin) == HIGH){
- switch(switches[i].pin){
- case 2: master_bat_on = 1; break;
- case 3: master_alt_on = 1; break;
- case 4: avionics_master_on = 1; break;
- case 5: fuel_pump_on = 1; break;
- case 6: carb_heat_on = 1; break;
- case 7: pitot_heat_on = 1; break;
- case 8: landing_gear_up = 1; break;
- case 9: lights_beacon_on = 1; break;
- case 10: lights_nav_on = 1; break;
- case 11: lights_stobe_on = 1; break;
- case 12: lights_taxi_on = 1; break;
- case 13: lights_landing_on = 1; break;
- default:
- Serial.println("not (yet) supported");
- }
- //Serial.println("setup is HIGH");
- switches[i].switchedOn = true;
- } else {
- //Serial.println("setup is LOW");
- switch(switches[i].pin){
- case 2: master_bat_off = 1; break;
- case 3: master_alt_off = 1; break;
- case 4: avionics_master_off = 1; break;
- case 5: fuel_pump_off = 1; break;
- case 6: carb_heat_off = 1; break;
- case 7: pitot_heat_off = 1; break;
- case 8: landing_gear_down = 1; break;
- case 9: lights_beacon_off = 1; break;
- case 10: lights_nav_off = 1; break;
- case 11: lights_strobe_off = 1; break;
- case 12: lights_taxi_off = 1; break;
- case 13: lights_landing_off = 1; break;
- default:
- Serial.println("not (yet) supported");
- }
- }
- }
- Serial.println("*** eos ***");
- }
- void loop(){
- FlightSim.update();
- if (FlightSim.isEnabled()) {
- digitalWrite(LED_BUILTIN, HIGH);
- } else {
- digitalWrite(LED_BUILTIN, LOW);
- }
- for(int i=0; i<NB_OF_SWITCHES; i++){
- /*String so = "false";
- if(switches[i].switchedOn){
- so = "true";
- }*/
- //Serial.println("---"+switches[i].label+" : " + so + "---");
- Bounce b = switches[i].bounce;
- b.update();
- int value = b.read();
- if(value==HIGH){
- if(! switches[i].switchedOn){
- Serial.println(switches[i].label + ": on");
- switch(switches[i].pin){
- case 2: master_bat_on = 1; break;
- case 3: master_alt_on = 1; break;
- case 4: avionics_master_on = 1; break;
- case 5: fuel_pump_on = 1; break;
- case 6: carb_heat_on = 1; break;
- case 7: pitot_heat_on = 1; break;
- case 8: landing_gear_up = 1; break;
- case 9: lights_beacon_on = 1; break;
- case 10: lights_nav_on = 1; break;
- case 11: lights_stobe_on = 1; break;
- case 12: lights_taxi_on = 1; break;
- case 13: lights_landing_on = 1; break;
- case 44: flaps_up = 1; break;
- case 45: flaps_down = 1; break;
- }
- }
- switches[i].switchedOn = true;
- }else{
- if(switches[i].switchedOn){
- Serial.println(switches[i].label + ": off");
- switch(switches[i].pin){
- case 2: master_bat_off = 1; break;
- case 3: master_alt_off = 1; break;
- case 4: avionics_master_off = 1; break;
- case 5: fuel_pump_off = 1; break;
- case 6: carb_heat_off = 1; break;
- case 7: pitot_heat_off = 1; break;
- case 8: landing_gear_down = 1; break;
- case 9: lights_beacon_off = 1; break;
- case 10: lights_nav_off = 1; break;
- case 11: lights_strobe_off = 1; break;
- case 12: lights_taxi_off = 1; break;
- case 13: lights_landing_off = 1; break;
- }
- switches[i].switchedOn = false;
- }
- }
- }
- delay(50);
- }
- // FUEL QTY UPDATE
- void updateFuelLight(long val){
- if(val > 0){
- Serial.println("fuel qty warning !");
- digitalWrite(fuelRedPin, HIGH);
- }else{
- digitalWrite(fuelRedPin, LOW);
- }
- }
- // STALL UPDATE
- void updateStallLight(long val){
- if(val > 0){
- Serial.println("stall warning !");
- digitalWrite(stallRedPin, HIGH);
- }else{
- digitalWrite(stallRedPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement