Advertisement
Guest User

Untitled

a guest
Feb 1st, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. #include <Bounce.h>
  2.  
  3. FlightSimCommand master_bat_on;
  4. FlightSimCommand master_bat_off;
  5. FlightSimCommand master_alt_on;
  6. FlightSimCommand master_alt_off;
  7. FlightSimCommand avionics_master_on;
  8. FlightSimCommand avionics_master_off;
  9. FlightSimCommand fuel_pump_on;
  10. FlightSimCommand fuel_pump_off;
  11. FlightSimCommand carb_heat_on;
  12. FlightSimCommand carb_heat_off;
  13. FlightSimCommand pitot_heat_on;
  14. FlightSimCommand pitot_heat_off;
  15. FlightSimCommand landing_gear_up;
  16. FlightSimCommand landing_gear_down;
  17. FlightSimCommand lights_beacon_on;
  18. FlightSimCommand lights_beacon_off;
  19. FlightSimCommand lights_nav_on;
  20. FlightSimCommand lights_nav_off;
  21. FlightSimCommand lights_stobe_on;
  22. FlightSimCommand lights_strobe_off;
  23. FlightSimCommand lights_taxi_on;
  24. FlightSimCommand lights_taxi_off;
  25. FlightSimCommand lights_landing_on;
  26. FlightSimCommand lights_landing_off;
  27. FlightSimCommand flaps_up;
  28. FlightSimCommand flaps_down;
  29.  
  30. FlightSimInteger fuel;
  31. FlightSimInteger stall;
  32.  
  33. struct SWITCH{
  34. int pin;
  35. String label;
  36. Bounce bounce;
  37. boolean switchedOn;
  38. };
  39.  
  40. const int NB_OF_SWITCHES = 14;
  41. SWITCH switches[] = {
  42. {2, "master bat", Bounce(2, 5), false}
  43. ,{3, "master alt", Bounce(3, 5), false}
  44. ,{4, "avionics master", Bounce(4, 5), false}
  45. ,{5, "fuel pump", Bounce(5, 5), false}
  46. ,{6, "carb heat", Bounce(6, 5), false}
  47. ,{7, "pitot heat", Bounce(7, 5), false}
  48. ,{8, "landing gear", Bounce(8, 5), false}
  49. ,{9, "lights beacon", Bounce(9, 5), false}
  50. ,{10, "lights nav", Bounce(10, 5), false}
  51. ,{11, "lights strobe", Bounce(11, 5), false}
  52. ,{12, "lights taxi", Bounce(12, 5), false}
  53. ,{13, "lights landing", Bounce(13, 5), false}
  54. ,{44, "flaps up", Bounce(44, 5), false}
  55. ,{45, "flaps down", Bounce(45, 5), false}
  56. };
  57.  
  58. int fuelRedPin = 14;
  59. int stallRedPin = 15;
  60.  
  61. void setup(){
  62. Serial.begin(38400);
  63. Serial.println("************");
  64. Serial.println("* new boot *");
  65. Serial.println("************");
  66.  
  67. pinMode(2, INPUT);
  68. pinMode(3, INPUT);
  69. pinMode(4, INPUT);
  70. pinMode(5, INPUT);
  71. pinMode(6, INPUT);
  72. pinMode(7, INPUT);
  73. pinMode(8, INPUT);
  74. pinMode(9, INPUT);
  75. pinMode(10, INPUT);
  76. pinMode(11, INPUT);
  77. pinMode(12, INPUT);
  78. pinMode(13, INPUT);
  79.  
  80. master_bat_on = XPlaneRef("sim/electrical/battery_1_on");
  81. master_bat_off = XPlaneRef("sim/electrical/battery_1_off");
  82. master_alt_on = XPlaneRef("sim/electrical/inverters_on");
  83. master_alt_off = XPlaneRef("sim/electrical/inverters_off");
  84. avionics_master_on = XPlaneRef("sim/systems/avionics_on");
  85. avionics_master_off = XPlaneRef("sim/systems/avionics_off");
  86. fuel_pump_on = XPlaneRef("sim/fuel/fuel_pump_1_on");
  87. fuel_pump_off = XPlaneRef("sim/fuel/fuel_pump_1_off");
  88. carb_heat_on = XPlaneRef("sim/engines/carb_heat_on");
  89. carb_heat_off = XPlaneRef("sim/engines/carb_heat_off");
  90. pitot_heat_on = XPlaneRef("sim/ice/pitot_heat_on");
  91. pitot_heat_off = XPlaneRef("sim/ice/pitot_heat_off");
  92. landing_gear_up = XPlaneRef("sim/flight_controls/landing_gear_up");
  93. landing_gear_down = XPlaneRef("sim/flight_controls/landing_gear_down");
  94. lights_beacon_on = XPlaneRef("sim/lights/beacon_lights_on");
  95. lights_beacon_off = XPlaneRef("sim/lights/beacon_lights_off");
  96. lights_nav_on = XPlaneRef("sim/lights/nav_lights_on");
  97. lights_nav_off = XPlaneRef("sim/lights/nav_lights_off");
  98. lights_stobe_on = XPlaneRef("sim/lights/strobe_lights_on");
  99. lights_strobe_off = XPlaneRef("sim/lights/strobe_lights_off");
  100. lights_taxi_on = XPlaneRef("sim/lights/taxi_lights_on");
  101. lights_taxi_off = XPlaneRef("sim/lights/taxi_lights_off");
  102. lights_landing_on = XPlaneRef("sim/lights/landing_lights_on");
  103. lights_landing_off = XPlaneRef("sim/lights/landing_lights_off") ;
  104. flaps_up = XPlaneRef("sim/flight_controls/flaps_up");
  105. flaps_down = XPlaneRef("sim/flight_controls/flaps_down");
  106.  
  107. pinMode(fuelRedPin, OUTPUT);
  108. fuel = XPlaneRef("sim/cockpit2/annunciators/fuel_quantity");
  109. fuel.onChange(updateFuelLight);
  110.  
  111. pinMode(stallRedPin, OUTPUT);
  112. stall = XPlaneRef("sim/cockpit2/annunciators/stall_warning");
  113. stall.onChange(updateStallLight);
  114.  
  115. for(int i=0; i<NB_OF_SWITCHES; i++){
  116. if(digitalRead(switches[i].pin) == HIGH){
  117. switch(switches[i].pin){
  118. case 2: master_bat_on = 1; break;
  119. case 3: master_alt_on = 1; break;
  120. case 4: avionics_master_on = 1; break;
  121. case 5: fuel_pump_on = 1; break;
  122. case 6: carb_heat_on = 1; break;
  123. case 7: pitot_heat_on = 1; break;
  124. case 8: landing_gear_up = 1; break;
  125. case 9: lights_beacon_on = 1; break;
  126. case 10: lights_nav_on = 1; break;
  127. case 11: lights_stobe_on = 1; break;
  128. case 12: lights_taxi_on = 1; break;
  129. case 13: lights_landing_on = 1; break;
  130. default:
  131. Serial.println("not (yet) supported");
  132. }
  133.  
  134. //Serial.println("setup is HIGH");
  135. switches[i].switchedOn = true;
  136. } else {
  137. //Serial.println("setup is LOW");
  138. switch(switches[i].pin){
  139. case 2: master_bat_off = 1; break;
  140. case 3: master_alt_off = 1; break;
  141. case 4: avionics_master_off = 1; break;
  142. case 5: fuel_pump_off = 1; break;
  143. case 6: carb_heat_off = 1; break;
  144. case 7: pitot_heat_off = 1; break;
  145. case 8: landing_gear_down = 1; break;
  146. case 9: lights_beacon_off = 1; break;
  147. case 10: lights_nav_off = 1; break;
  148. case 11: lights_strobe_off = 1; break;
  149. case 12: lights_taxi_off = 1; break;
  150. case 13: lights_landing_off = 1; break;
  151. default:
  152. Serial.println("not (yet) supported");
  153. }
  154.  
  155. }
  156. }
  157.  
  158. Serial.println("*** eos ***");
  159. }
  160.  
  161. void loop(){
  162. FlightSim.update();
  163.  
  164. if (FlightSim.isEnabled()) {
  165. digitalWrite(LED_BUILTIN, HIGH);
  166. } else {
  167. digitalWrite(LED_BUILTIN, LOW);
  168. }
  169.  
  170. for(int i=0; i<NB_OF_SWITCHES; i++){
  171.  
  172. /*String so = "false";
  173. if(switches[i].switchedOn){
  174. so = "true";
  175. }*/
  176.  
  177. //Serial.println("---"+switches[i].label+" : " + so + "---");
  178.  
  179. Bounce b = switches[i].bounce;
  180. b.update();
  181.  
  182. int value = b.read();
  183.  
  184. if(value==HIGH){
  185. if(! switches[i].switchedOn){
  186. Serial.println(switches[i].label + ": on");
  187. switch(switches[i].pin){
  188. case 2: master_bat_on = 1; break;
  189. case 3: master_alt_on = 1; break;
  190. case 4: avionics_master_on = 1; break;
  191. case 5: fuel_pump_on = 1; break;
  192. case 6: carb_heat_on = 1; break;
  193. case 7: pitot_heat_on = 1; break;
  194. case 8: landing_gear_up = 1; break;
  195. case 9: lights_beacon_on = 1; break;
  196. case 10: lights_nav_on = 1; break;
  197. case 11: lights_stobe_on = 1; break;
  198. case 12: lights_taxi_on = 1; break;
  199. case 13: lights_landing_on = 1; break;
  200. case 44: flaps_up = 1; break;
  201. case 45: flaps_down = 1; break;
  202. }
  203. }
  204.  
  205. switches[i].switchedOn = true;
  206. }else{
  207. if(switches[i].switchedOn){
  208. Serial.println(switches[i].label + ": off");
  209. switch(switches[i].pin){
  210. case 2: master_bat_off = 1; break;
  211. case 3: master_alt_off = 1; break;
  212. case 4: avionics_master_off = 1; break;
  213. case 5: fuel_pump_off = 1; break;
  214. case 6: carb_heat_off = 1; break;
  215. case 7: pitot_heat_off = 1; break;
  216. case 8: landing_gear_down = 1; break;
  217. case 9: lights_beacon_off = 1; break;
  218. case 10: lights_nav_off = 1; break;
  219. case 11: lights_strobe_off = 1; break;
  220. case 12: lights_taxi_off = 1; break;
  221. case 13: lights_landing_off = 1; break;
  222. }
  223.  
  224. switches[i].switchedOn = false;
  225. }
  226. }
  227. }
  228.  
  229. delay(50);
  230. }
  231.  
  232. // FUEL QTY UPDATE
  233. void updateFuelLight(long val){
  234. if(val > 0){
  235. Serial.println("fuel qty warning !");
  236. digitalWrite(fuelRedPin, HIGH);
  237. }else{
  238. digitalWrite(fuelRedPin, LOW);
  239. }
  240. }
  241.  
  242. // STALL UPDATE
  243. void updateStallLight(long val){
  244. if(val > 0){
  245. Serial.println("stall warning !");
  246. digitalWrite(stallRedPin, HIGH);
  247. }else{
  248. digitalWrite(stallRedPin, LOW);
  249. }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement