Guest User

Untitled

a guest
Sep 9th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. /*
  2. arduino aircraft lighting
  3. contains various bits that were ripped from strandtest, forum.arduino.cc, arduino IDE
  4. examples, and others, then heavily cut down and commented to the best of my ability.
  5.  
  6. modify this to suit your needs, it's working fine for me now.
  7.  
  8. -floz
  9. */
  10.  
  11. #include <Adafruit_NeoPixel.h>
  12. #ifdef __AVR__
  13. #include <avr/power.h>
  14. #endif
  15.  
  16. //data-pin for the neopixels (output)
  17. #define PIN 6
  18.  
  19. //channel on your hobby receiver connects to this digital pin (input)
  20. #define PWM_SOURCE 5
  21.  
  22. //how long between strobe flashes/battery checks
  23. const long interval = 3750;
  24. //timer var
  25. unsigned long previousMillis = 0;
  26.  
  27. //el togglodyte supremo!
  28. int LightState = 1;
  29. int LastLightState = 0;
  30.  
  31. //magic sauce
  32. Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ400);
  33.  
  34.  
  35. void setup()
  36. {
  37.  
  38. strip.begin(); // init required?
  39. strip.show(); // Initialize all pixels to 'off'
  40. Serial.begin(9600); // start serial output
  41. }
  42. void nav_lights(){
  43. //red/green FAA style with added strobe
  44. strip.setPixelColor(0, 0,255,0);
  45. strip.setPixelColor(1,255,0,0);
  46. strip.show();
  47. delay(250);
  48.  
  49. }
  50. void landing_lights(){
  51. //bright warm white
  52. strip.setPixelColor(0, 255,255,196);
  53. strip.setPixelColor(1, 255,255,196);
  54. strip.show();
  55. delay(250);
  56. }
  57. void battery_timer(){
  58. //after x minutes (default 10) give the pilot a friendly warning flash
  59. Serial.print(millis());
  60. Serial.println(" battery warning - uptime exceeds 10 mins!!!");
  61.  
  62. strip.setPixelColor(0, 255,255,0);
  63. strip.setPixelColor(1, 0,0,0);
  64. strip.show();
  65. delay(150);
  66. strip.setPixelColor(1, 255,255,0);
  67. strip.setPixelColor(0, 0,0,0);
  68. strip.show();
  69. delay(150);
  70.  
  71. }
  72.  
  73. void strobe(){
  74. // added strobe thingie
  75. Serial.println(" MS do strobe");
  76.  
  77. strip.setPixelColor(0, 255,255,255);
  78. strip.setPixelColor(1, 255,255,255);
  79. strip.show();
  80. delay(100);
  81. LightState = LastLightState;
  82. }
  83.  
  84. void loop() {
  85. //the rest of this is kind of sloppy, but it seems to work.
  86. if (LightState == 1){
  87. nav_lights();
  88. }
  89. if (LightState == 0){
  90. landing_lights();
  91. }
  92.  
  93.  
  94. unsigned long currentMillis = millis();
  95. //someone else's work, from blinkwithoutdelay example.
  96. if (currentMillis - previousMillis >= interval) {
  97.  
  98. // this huge number (600000) is ten minutes in milliseconds
  99. if (millis() >= 600000){
  100. battery_timer();
  101. return; //ymmv, comment out?
  102. }
  103. Serial.print(millis());
  104. // save the last time you blinked the strobe
  105. previousMillis = currentMillis;
  106. if (LightState == 0){
  107. //if we're using landing lights, don't bother.
  108. Serial.println(" MS no strobe");
  109. return;
  110. }
  111. LastLightState = LightState; //var to return to nav lights after strobe
  112. strobe(); //give us a quick flash
  113. }
  114.  
  115. int pwmin = pulseIn(PWM_SOURCE, HIGH, 20000); //read the PWM line (default pin 5)
  116. if (pwmin >= 1400){ //from the hobby receiver
  117. LastLightState = LightState; // 1400 worked for me with a toggle
  118. LightState = 0; //landing lights // switch on a flysky fs-t6
  119. if (LastLightState != LightState){ // ymmv, down position was ~980 and
  120. Serial.print(pwmin); // up position was ~1900 on my gear
  121. Serial.println(" PWM landing lights");
  122. } // all to toggle the lights
  123. }else{
  124. LastLightState = LightState; // <--- toggle t'other way
  125. LightState = 1; //nav lights
  126. if (LastLightState != LightState){ // aren't you glad i added
  127. Serial.print(pwmin); // really verbose serial output now?
  128. Serial.println(" PWM nav lights");
  129. }
  130. }
  131.  
  132. }
Add Comment
Please, Sign In to add comment