Results 1 to 8 of 8
  1. #1
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Jan 2014
    Location
    Aus
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Annunciator - Master Warning code help

    Hello All,

    I am starting to refine the components of my build and after some fantastic guidance from the forum with my comm panel I am hoping someone might be able to help me refine my annunciator code.


    I have everything working, except for the master warning flasher. I am using Jim's code example, but what I want the master caution to trigger is as follows:


    When any master warning state is active I want the master warning light to flash until a button is pressed, then reset and await a new warning. Basically this is how it works on a real aircraft.


    I think I need to run some sort of loop (for the flasher) that will be interrupted when the button is pressed but I'm not sure how to do it. It's had me stumped for a while, if anyone can help I would be grateful.


    Regards,


    Michael

  2. #2
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    Michael,
    Here is some code which will work your master warning. It's done without delays.

    Code:
    long unsigned flashTimer;
    boolean flasher;
    boolean warning1_FSX;
    boolean warning1_acknowledged;
    boolean warning1_latch;
    boolean warning1_active;
    boolean warning2_FSX;
    boolean warning2_acknowledged;
    boolean warning2_latch;
    boolean warning2_active;
    boolean masterWarn;
    boolean acknowledge;
    
    /////////////////////////////////
    void setup() {
      pinMode(30, INPUT);
      pinMode(31, OUTPUT);
      flashTimer=millis();
      warning1_latch=0;
      warning2_latch=0;
    } //end of void setup
    /////////////////////////////////
    void loop()  {
      acknowledge=digitalRead(30); 
     //**Set up flash timer**
     //**adjust timer values 1000&3000 to suit your preference****
      if (millis()>=flashTimer+1000) flasher=1;
      if (millis()>=flashTimer+3000) {
        flasher=0;
        flashTimer=millis();
      } //end if
       
      //**Check status of warning1**
      if (warning1_FSX==1) warning1_latch=1;
      if ((warning1_latch==1)&&(acknowledge==1)) warning1_acknowledged=1;
      if ((warning1_FSX==0)&&(warning1_acknowledged==1)) {
        warning1_latch=0;
        warning1_acknowledged=0;
      }//end if
     if ((warning1_latch==1)&&(warning1_acknowledged=0)) warning1_active=1; 
     else warning1_active=0;
     
       //**Check status of warning2**
      if (warning2_FSX==1) warning2_latch=1;
      if ((warning2_latch==1)&&(acknowledge==1)) warning2_acknowledged=1;
      if ((warning2_FSX==0)&&(warning2_acknowledged==1)) {
        warning2_latch=0;
        warning2_acknowledged=0;
      }//end if
      if ((warning2_latch==1)&&(warning2_acknowledged=0)) warning2_active=1; 
      else warning2_active=0;
    
    //*** if any of the warning_active bits are set, flash master warning  
      if ((warning1_active==1)&&(flasher==1)) masterWarn=1;
      if ((warning2_active==1)&&(flasher==1)) masterWarn=1;
      if (flasher==0) masterWarn=0;
      
    }// end void loop

  3. #3
    10+ Posting Member
    Join Date
    Aug 2014
    Location
    London
    Posts
    23
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    Quote Originally Posted by SteveL View Post
    Michael,
    Here is some code which will work your master warning. It's done without delays.

    Code:
    long unsigned flashTimer;
    boolean flasher;
    boolean warning1_FSX;
    boolean warning1_acknowledged;
    boolean warning1_latch;
    boolean warning1_active;
    boolean warning2_FSX;
    boolean warning2_acknowledged;
    boolean warning2_latch;
    boolean warning2_active;
    boolean masterWarn;
    boolean acknowledge;
    
    /////////////////////////////////
    void setup() {
      pinMode(30, INPUT);
      pinMode(31, OUTPUT);
      flashTimer=millis();
      warning1_latch=0;
      warning2_latch=0;
    } //end of void setup
    /////////////////////////////////
    void loop()  {
      acknowledge=digitalRead(30); 
     //**Set up flash timer**
     //**adjust timer values 1000&3000 to suit your preference****
      if (millis()>=flashTimer+1000) flasher=1;
      if (millis()>=flashTimer+3000) {
        flasher=0;
        flashTimer=millis();
      } //end if
       
      //**Check status of warning1**
      if (warning1_FSX==1) warning1_latch=1;
      if ((warning1_latch==1)&&(acknowledge==1)) warning1_acknowledged=1;
      if ((warning1_FSX==0)&&(warning1_acknowledged==1)) {
        warning1_latch=0;
        warning1_acknowledged=0;
      }//end if
     if ((warning1_latch==1)&&(warning1_acknowledged=0)) warning1_active=1; 
     else warning1_active=0;
     
       //**Check status of warning2**
      if (warning2_FSX==1) warning2_latch=1;
      if ((warning2_latch==1)&&(acknowledge==1)) warning2_acknowledged=1;
      if ((warning2_FSX==0)&&(warning2_acknowledged==1)) {
        warning2_latch=0;
        warning2_acknowledged=0;
      }//end if
      if ((warning2_latch==1)&&(warning2_acknowledged=0)) warning2_active=1; 
      else warning2_active=0;
    
    //*** if any of the warning_active bits are set, flash master warning  
      if ((warning1_active==1)&&(flasher==1)) masterWarn=1;
      if ((warning2_active==1)&&(flasher==1)) masterWarn=1;
      if (flasher==0) masterWarn=0;
      
    }// end void loop
    Hello

    Please excuse my complete ignorance (I have just purchased an Arduino Mega and started playing with Jims Code).

    I can see Mike was after a way to have the Master Caution output (from his NGX?) output to the board, and Im after the same plus a little more . If you dont mind can I ask a few questions?

    1. The above code - Am I correct in stating I can add this code to an exisiting sketch, lets say Jims Annunciator \ Radio Sketch?
    2. The LED for the caution - does this connect to one of the pins 30 or 31, or perhaps those pins are reservered for the master caution reset button?
    3. If the above is for the switch, can youpoint me in the direction for setting up a LED indication that master caution is active
    4. Using link2fs, would I have to enable anything else other than A1 in the annunicator section?

    Sorry, so many questions from someone who is trying and willing to learn! I might post a seperate question reagrding the AP/AT/FMC warning lights in the 737NGX

    Many thanks

  4. #4
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    Michael,
    This is just a snippet of code to execute the button/LED logic you requested. Although it is a complete sketch, it includes no data exchange with fsx. You need to modify this code for your specific requirements and then add it to your existing data exchange sketch. This code uses two example warning signals, “warning1” and “warning2”, which represent any two aircraft conditions. It does not use a master caution signal from fsx, this signal is derived by logic in the Arduino code so that it can be manipulated to suit your conditions. When either of the individual warning conditions is ON, the LED will flash until the Acknowledge button is pressed, and then hold steady until the warning is removed at which time the LED turns off. The constants used in the flash timer section control the ON and OFF timing for the LED flashing, change them to make the flashing faster or slower to suit your preferences.

    Your actual application will have many warning signals, not just two. You will need to change the names I used from warning (1 or 2) to the actual names of your warning conditions, and add additional ones for your other conditions by duplicating the logic for the two examples shown. You can have as many of these as you need.

    The Master Caution LED for your panel is shown on pin 31, but you can use any available digital pin, 31 is just an illustration. Likewise, your acknowledge button is shown using pin 30 for illustration purposes.

    You should first make a list of the warning conditions you want to trigger the master caution LED, and then modify this code to match the correct warning conditions and pins used for the LED and switch, and then add the code to your existing sketch. If you are not already reading all of the warning conditions, you need to add them via link2fs. Make sure you use the same names for the extracted data as you use in the LED logic. The precise code to use to get these signals will depend on what warnings you want to use; I fly light GA and can’t help you with the specific 737NGX extractions.




  5. #5
    10+ Posting Member
    Join Date
    Aug 2014
    Location
    London
    Posts
    23
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    Thanks Steve - Sorry, it wasnt clear it was me who asked the question and not Mike - I have pointed this out as Mike is allot further along the "understanding" path than I, so don't want to cause him any offence.

  6. #6
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    hi , i have added this code to my existing code that i use for the autopilot. my autopilot is working fine with the 7 segment and the buttons are also working fine. when i add the other annunciators led they are working fine aswell. the fuel light goes on but cant get the master warning to work. i have my input pin on 30 and my led on 21(output) but i miss something that it do not work. as in the code the led must go on 31 but nowhere in the code it is specified that it should read to pin 31. i have tried all the output pins to see if the led go on but nothing happens even the switch do not work . please assistregards andre

  7. #7
    10+ Posting Member
    Join Date
    Nov 2011
    Location
    Rotorua, New Zealand
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    Hi here is the sketch that I am using with the help from BushPilotWannabe.
    This code doesn't do exactly what you want with your master caution led but it does add a test button into the mix to test all led's and pizo are working before startup.

    /*
    Re: re. Link2fs Announciator panel 7 lights and 2 pushbutton
    Push-To-Test Switch added by BushPilotWannabe July 2015
    MOVE THE COMMENT MARKERS from line#2 to line#3
    test using FSX C172SP Skyhawk audio panel and Link2FS Extractions1 boxes N, O, P, Q, U, R & S
    both void SLASH() and void EQUALS() can be left intact. The input from Link2FS Extractions determines the output
    */


    int AnunPinNo[7] = {2, 3, 4, 5, 6, 7, 8};// the selected pins with LED's
    // char AnunIdent2[7] = {'E','F','L','Q','V','b','f'};//Selected items in "Annunciators" in Multi
    char AnunIdent2[7] = {'N','O','P','Q','U','R','S'};
    long AnunButtonStop = 0;
    boolean ButtonStopEnable = 0;
    //
    int AnunPinValNew[7] = {0,0,0,0,0,0,0};//Array for pin values (The new readings)
    int AnunPinValOld[7] = {0,0,0,0,0,0,0};//Array for pin values (The old readings)
    int count = 0; //for array reading
    int counterTrigger = 0;// Used for triggering the flashing LED's
    int counterTriggerOld = 0;
    long counter = 1; // Counter for read loops TO TIME THE FLASHING
    int CodeIn;// Gets the serial read
    int PTTButton = 10;
    int bipassSwitchPins = 0; // =1 avoids repetitive pin assignments
    int piezo = 11;//Was 11
    int dummy; // dummy output until LEDs are restored after test
    int Anunbutton = 12;// the cancell alarm button in the Annunciator panel
    int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button






    void setup(){
    for (count=0;count<7;count++) {// we make all the Anun declarations at once
    // Be careful with the above line.(Dont involve a pin that will have a switch on it ,, it can fry your pin or card)
    pinMode(AnunPinNo[count], OUTPUT);
    digitalWrite(AnunPinNo[count], LOW);
    }
    pinMode(PTTButton,INPUT_PULLUP);
    digitalWrite(PTTButton,HIGH);
    pinMode(piezo, OUTPUT); // done the piezo seperately for clearer coding
    digitalWrite(piezo, LOW);
    pinMode(Anunbutton, INPUT_PULLUP); // Cancell button on Anunnciators
    pinMode(dummy,OUTPUT);
    digitalWrite(Anunbutton, HIGH);
    Serial.begin(115200);
    }




    void loop() {
    {OTHER();}
    {ANNUNBUTTON();}
    {PUSHTOTEST();}
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();}
    if (CodeIn == '<') {LESSTHAN();}
    if (CodeIn == '?') {QUESTION();}
    if (CodeIn == '/') {SLASH();}
    }
    }




    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());
    }




    void OTHER(){
    // Normal "run" stuff in here
    }




    void EQUALS(){
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }


    /*
    CodeIn = getChar();
    switch(CodeIn) {
    case 'A':
    //Do something
    break;


    case 'W':
    //Do something
    break;


    case 'a':
    //Do something
    break;
    //etc etc etc
    }
    }
    */




    void LESSTHAN(){ // The first identifier was "<"
    //Do something (See void EQUALS)
    }




    void QUESTION(){ // The first identifier was "?"
    //Do something (See void EQUALS)
    }




    void SLASH(){ // The first identifier was "/" (Annunciators)
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }




    void ANNUNBUTTON(){
    counter = counter + 1;
    if (counter < 50000){counterTrigger = 0;}else {counterTrigger = 1;}
    if (counter > 100000) {counter = 1;}
    if (digitalRead(Anunbutton)==0){
    digitalWrite(piezo, LOW);
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1){AnunPinValOld[count] = 3;}
    }
    }
    if (counterTrigger != counterTriggerOld) {
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 3) {
    if (counterTrigger == 1){digitalWrite(AnunPinNo[count], HIGH);}
    if (counterTrigger == 0){digitalWrite(AnunPinNo[count], LOW);}
    }
    }
    counterTriggerOld = counterTrigger;
    }
    }






    void PUSHTOTEST()
    {
    if (digitalRead(10)==0){
    if (bipassSwitchPins != 1){
    for (count=0; count<7;count++) {AnunPinNo[count] =13; }
    piezo = 13;
    for (count=2; count<9; count++) digitalWrite(count,HIGH);
    digitalWrite(11,HIGH);
    bipassSwitchPins = 1;
    }
    AnunButtonStop = millis() + 400;
    ButtonStopEnable = 1;
    }
    // cleanup
    if (((millis()) > AnunButtonStop) && ButtonStopEnable == 1){
    for (count=2; count<9; count++) {digitalWrite(count,LOW); }
    {digitalWrite(11,LOW); digitalWrite(13,LOW);}
    {AnunPinNo[0] = 2; AnunPinNo[1] = 3; AnunPinNo[2] = 4; AnunPinNo[3] = 5;}
    {AnunPinNo[4] = 6; AnunPinNo[5] = 7; AnunPinNo[6] = 8;}
    piezo= 11;
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1) {digitalWrite(AnunPinNo[count],AnunPinValOld[count]); digitalWrite(piezo,HIGH);}
    {ButtonStopEnable = 0; bipassSwitchPins = 0;} // remove enable keys on exit
    }
    }
    }

  8. #8
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Annunciator - Master Warning code help

    thanks a lot will give it a try