Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- arduino aircraft lighting update 1
- 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 = 5050;
- //timer var
- unsigned long previousMillis = 0;
- //el togglodyte supremo!
- int LightState = 1;
- int LastLightState = 0;
- //magic sauce for neopixel/ws2812b
- //check strandtest or other examples for further info
- //you can instantiate multiples for all kinds of effects
- Adafruit_NeoPixel leds = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ400);
- void setup()
- {
- leds.begin(); // init the instance
- leds.show(); // Initialize all pixels to 'off'
- Serial.begin(9600); // start serial output
- }
- void nav_lights(){
- //red/green FAA style
- leds.setPixelColor(0, 0,255,0);
- leds.setPixelColor(1,255,0,0);
- leds.show();
- }
- void landing_lights(){
- //bright warm white
- leds.setPixelColor(0, 255,255,196);
- leds.setPixelColor(1, 255,255,196);
- leds.show();
- }
- void battery_timer(){
- //after x minutes (default 10) give the pilot a friendly warning flash
- //and refuse to exit this mode until reset/powered down
- leds.setPixelColor(0, 255,255,0);
- leds.setPixelColor(1, 0,0,0);
- leds.show();
- delay(150);
- leds.setPixelColor(1, 255,255,0);
- leds.setPixelColor(0, 0,0,0);
- leds.show();
- delay(150);
- LightState = 3;
- }
- void strobe(){
- // added strobe thingie
- leds.setPixelColor(0, 255,255,255);
- leds.setPixelColor(1, 255,255,255);
- leds.show();
- delay(60);
- LightState = LastLightState;
- return;
- }
- void strobe_loop(){
- // rapid wingtip flashes of white/off
- leds.setPixelColor(0, 255,255,255);
- leds.setPixelColor(1, 255,255,255);
- leds.show();
- delay(100);
- leds.setPixelColor(0, 0,0,0);
- leds.setPixelColor(1, 0,0,0);
- leds.show();
- delay(100);
- }
- void loop() {
- //cleaned it up some, using switch/case now
- if (LightState == 0){
- nav_lights();
- }
- if (LightState == 1){
- landing_lights();
- }
- if (LightState == 2){
- strobe_loop();
- }
- if (LightState ==3){
- battery_timer();
- }
- /*
- if (LightState ==4){ //add extra functions like this.
- strobe_loop();
- }
- */
- unsigned long currentMillis = millis();
- //someone else's work, from blinkwithoutdelay example.
- if (currentMillis - previousMillis >= interval) {
- // this huge number (600000) is ten minutes in milliseconds
- // ( min * 60 ) * 1000 = ms
- // i adjusted to 6 minutes while learning to fly
- if (millis() >= 480000){
- battery_timer();
- return; //ymmv, comment out?
- }
- previousMillis = currentMillis;
- if (LightState != 0){ //strobe check
- //if we're not using nav lights, don't bother
- 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)
- //map the value to however many choices you want to have
- int selection = map(pwmin, 1000,1900,0,2);
- Serial.print("PWM: ");
- Serial.print(pwmin);
- if (LightState == 0){
- Serial.print(" nav lights ");
- }
- if (LightState == 1){
- Serial.print(" landing lights ");
- }
- if (LightState == 2){
- Serial.print(" strobe lights ");
- }
- Serial.print(" time: ");
- Serial.println(millis());
- switch (selection) { //what mode are we in according to pwm?
- case 0:
- LightState = 0; //nav lights
- break;
- case 1:
- LightState = 1; //landing lights
- break;
- case 2:
- LightState = 2; // strobes
- break;
- /*
- case 3: //add extra functions this way
- LightState = 3; //battery warning flash test
- Serial.println("battery strobe test");
- break;
- case 4:
- LightState = 4;
- Serial.println("state #4");
- break;
- */
- }
- //Serial.print("time: ");
- //Serial.println(millis());
- //delay(100); //purely for debugging otherwise the console is spammmmmm
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement