Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- arduino aircraft lighting
- contains various bits that were ripped from strandtest, forum.arduino.cc, arduino IDE
- examples, and others, then heavily cut down and commented to the best of my ability.
- modify this to suit your needs, it's working fine for me now.
- -floz
- */
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- //data-pin for the neopixels (output)
- #define PIN 6
- //channel on your hobby receiver connects to this digital pin (input)
- #define PWM_SOURCE 5
- //how long between strobe flashes/battery checks
- const long interval = 3750;
- //timer var
- unsigned long previousMillis = 0;
- //el togglodyte supremo!
- int LightState = 1;
- int LastLightState = 0;
- //magic sauce
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ400);
- void setup()
- {
- strip.begin(); // init required?
- strip.show(); // Initialize all pixels to 'off'
- Serial.begin(9600); // start serial output
- }
- void nav_lights(){
- //red/green FAA style with added strobe
- strip.setPixelColor(0, 0,255,0);
- strip.setPixelColor(1,255,0,0);
- strip.show();
- delay(250);
- }
- void landing_lights(){
- //bright warm white
- strip.setPixelColor(0, 255,255,196);
- strip.setPixelColor(1, 255,255,196);
- strip.show();
- delay(250);
- }
- void battery_timer(){
- //after x minutes (default 10) give the pilot a friendly warning flash
- Serial.print(millis());
- Serial.println(" battery warning - uptime exceeds 10 mins!!!");
- strip.setPixelColor(0, 255,255,0);
- strip.setPixelColor(1, 0,0,0);
- strip.show();
- delay(150);
- strip.setPixelColor(1, 255,255,0);
- strip.setPixelColor(0, 0,0,0);
- strip.show();
- delay(150);
- }
- void strobe(){
- // added strobe thingie
- Serial.println(" MS do strobe");
- strip.setPixelColor(0, 255,255,255);
- strip.setPixelColor(1, 255,255,255);
- strip.show();
- delay(100);
- LightState = LastLightState;
- }
- void loop() {
- //the rest of this is kind of sloppy, but it seems to work.
- if (LightState == 1){
- nav_lights();
- }
- if (LightState == 0){
- landing_lights();
- }
- unsigned long currentMillis = millis();
- //someone else's work, from blinkwithoutdelay example.
- if (currentMillis - previousMillis >= interval) {
- // this huge number (600000) is ten minutes in milliseconds
- if (millis() >= 600000){
- battery_timer();
- return; //ymmv, comment out?
- }
- Serial.print(millis());
- // save the last time you blinked the strobe
- previousMillis = currentMillis;
- if (LightState == 0){
- //if we're using landing lights, don't bother.
- Serial.println(" MS no strobe");
- return;
- }
- LastLightState = LightState; //var to return to nav lights after strobe
- strobe(); //give us a quick flash
- }
- int pwmin = pulseIn(PWM_SOURCE, HIGH, 20000); //read the PWM line (default pin 5)
- if (pwmin >= 1400){ //from the hobby receiver
- LastLightState = LightState; // 1400 worked for me with a toggle
- LightState = 0; //landing lights // switch on a flysky fs-t6
- if (LastLightState != LightState){ // ymmv, down position was ~980 and
- Serial.print(pwmin); // up position was ~1900 on my gear
- Serial.println(" PWM landing lights");
- } // all to toggle the lights
- }else{
- LastLightState = LightState; // <--- toggle t'other way
- LightState = 1; //nav lights
- if (LastLightState != LightState){ // aren't you glad i added
- Serial.print(pwmin); // really verbose serial output now?
- Serial.println(" PWM nav lights");
- }
- }
- }
Add Comment
Please, Sign In to add comment