/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you’re unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc This example code is in the public domain. Modified 8 May 2014 by Scott Fitzgerald */ //the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } //the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } /* Annunciator Panel Sketch This program will light up the Annunciator Panel based on current status of the Aircraft. The circuit: * Momentary switch attached from pin 4 to ground (Nose Gear) * Momentary switch attached from pin 6 to ground (Canopy) * Momentary switch attached from pin 7 to ground (Landing Brake) * Momentary switch attached from pin 5 to ground (alarm silence) * sounder attached from pin 3 to ground * Potentiometer connected to A0 (Throttle position) * Built-in/External LED on pin 13 (green Gear Up) * External LED on pin 12 (green Canopy open) * External LED on pin 11 (greep landing brake deployed) * External LED on pin 10 (RED Master Caution) Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal 20K-ohm resistor is pulled to 5V. This configuration causes the input to read HIGH when the switch is open, and LOW when it is closed. created 29 Mar 2015 by Tom Brusehaver This example code is in the public domain */ #include // Give all the pins a name. Change the pin numbers here and // the logic won't have to change. int GEAR_SW =4; int CANOPY_SW=6; int LB_SW =7; // Silence pushbutton. Once button released, alarm is silenced for 5 seconds. int SILENCE_SW=5; // Alarm sounder is on pin 3 int ALARM_OUT = 3; // Green LEDs on pins 10, 12 and 13. int GEAR_IND =13; int CANOPY_IND =12; int LB_IND =10; // red master alarm is on pin 9 int MASTER_IND =9; // Throttle position is analog int THROTTLE_IN = 0; // analog pin 0 int THROTTLE_CLOSED=100; // fast idle int THROTTLE_MAX=900; // takeoff power void setup(){ //configure input pins as an input and enable the internal pull-up resistor pinMode(GEAR_SW, INPUT_PULLUP); pinMode(CANOPY_SW, INPUT_PULLUP); pinMode(LB_SW, INPUT_PULLUP); pinMode(SILENCE_SW, INPUT_PULLUP); // configure output pins for output. pinMode(ALARM_OUT, OUTPUT); pinMode(GEAR_IND, OUTPUT); pinMode(CANOPY_IND, OUTPUT); pinMode(LB_IND, OUTPUT); pinMode(MASTER_IND, OUTPUT); } /** * Read all the switches and call the display function */ void loop(){ //read the switch value into a variable int gearVal = digitalRead(GEAR_SW); int canopyVal = digitalRead(CANOPY_SW); int landBrakeVal = digitalRead(LB_SW); int silenceVal = digitalRead(SILENCE_SW); int throttleVal = analogRead(THROTTLE_IN); display(gearVal, canopyVal, landBrakeVal, throttleVal, silenceVal); } /** * check the logic to see if there is a master warning to display * returns 1 if the master warning should be set. */ int isAlertState(int gearVal, int canopyVal, int lbVal, int throttleVal) { int alert = 0; // throttle closed, and landing gear up if ((throttleVal <= THROTTLE_CLOSED) && (!gearVal)) { alert = 1; } // throttle max and canopy not closed, and landing brake not up if ((throttleVal >= THROTTLE_MAX) && (canopyVal) && (lbVal)) { alert = 1; } return alert; } /** * Process all the logic, to allow displaying LEDs in proper state, and * handle master alarm state, including sound. */ void display(int gearVal, int canopyVal, int lbVal, int throttleVal, int silenceVal) { int alert = 0; // gap is the cycle time for the tone. state is the tone state. static int gap=0; static int state=LOW; // silenced at is the time the alarm was silenced at. static time_t silencedAt=0; // Keep in mind the pullup means the pushbutton's // logic is inverted. It goes HIGH when it's open, // and LOW when it's pressed.: digitalWrite(GEAR_IND, gearVal); digitalWrite(CANOPY_IND, canopyVal); digitalWrite(LB_IND, lbVal); // The silence button is open normally. Logic is reversed. if (!silenceVal) { silencedAt = now(); } alert = isAlertState(gearVal, canopyVal, lbVal, throttleVal); // output the master alarm status if (alert) { digitalWrite(MASTER_IND, HIGH); // generate a tone if (gap++ == 4) { state = !state; gap = 0; } if (now() > silencedAt + 5) { digitalWrite(ALARM_OUT, state); } } else { digitalWrite(MASTER_IND, LOW); digitalWrite(ALARM_OUT, LOW); } }