Saturday 20 January 2018

Model Aircraft Navigation Light Controller

Brian asked whether I could build him a circuit to flash the navigation lights on a model aircraft in a realistic manner.  He had previously provided me with an Arduino Nano which would easily be capable of the task, actually it seems like overkill, but software does make this kind of thing very easy.

Searching the Internet yielded a diagram explaining the actual light flash timings for an Airbus, which seems like a fair starting point.

(Source: UTC Aerospace Systems)

Programming the Arduino to emulate the timings behind this behaviour required a simple state machine.
The way I've coded it here isn't going to be very power-efficient though, since it's spinning around the loop all the time. It would be better to add some sleep logic and make it interrupt driven. Maybe later.

const int pinWingL =  2;
const int pinWingR =  3;
const int pinTail =  4;
const int pinBeacon =  LED_BUILTIN;

// Start time of state machine
unsigned long startTime = 0;

// Current state
int state = 0;

void setup() {
  // set the digital pins as output:
  pinMode(pinWingL, OUTPUT);
  pinMode(pinWingR, OUTPUT);
  pinMode(pinTail, OUTPUT);
  pinMode(pinBeacon, OUTPUT);
}


void loop() {

  unsigned long currentTime = millis();
  long deltaTime = currentTime - startTime;
  
  switch (state) {
    case (0): 
    default:
      startTime = currentTime;
      setBeacon(LOW);
      setWing(HIGH);
      setTail(HIGH);
      state = 1;
      break;

    case (1):
      if (deltaTime > 50) {
        setWing(LOW);
        state = 2;
      }
      break;

    case (2): 
      if (deltaTime > 100) {
        setWing(HIGH);
        setTail(LOW);
        state = 3;
      }
      break;

    case (3):
      if (deltaTime > 150) {
        setWing(LOW);
        state = 4;
      }
      break;

    case (4):
      if (deltaTime > 500) {
        setBeacon(HIGH);
        state = 5;
      }
      break;

    case (5):
      if (deltaTime > 600) {
        setBeacon(LOW);
        state = 6;
      }
      break;

    case (6):
      if (deltaTime > 999) {
        startTime = currentTime;
        state = 0;
      }
      break;
  }         
}

void setWing(int state) {
  digitalWrite(pinWingL, state);
  digitalWrite(pinWingR, state);
}

void setTail(int state) {
  digitalWrite(pinTail, state);
}

void setBeacon(int state) {
  digitalWrite(pinBeacon, state);
}

No comments:

Post a Comment