Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Question Too Much Data Too Fast???

    Santa was good to me and I got a Mega in my stocking!

    So now I have assembled all the snip-its of code I wrote on my old UNO in one sketch and loaded it on the Mega. I have attempted two different approaches and both fail under the same circumstance. When I have all the extractions checked off that I want to send to the board things seem to go along ok until either a rapid change in altitude, I am monitoring extraction "D" for AGL, or I lower/raise the gear causing the Gear Position Extractions "I", "J", "K" to cycle rapidly between 0 and 100.

    Either of those actions seem to freeze up the MEGA and I have to reset it to get things working again. I thought it might be that my baud rate or cycle time where too high so I tested it at the slowest baud rate, slowed cycle time to 500 msec, and the used 0, 6, and 30 on the Refresh Timer settings the same problem occurs.

    Is there a Serial Read buffer on the Mega that might be over flowing ? If so is there a way to increase its size ? Any other thoughts on what might be causing this?

    I am using the following extractions:
    • D Ground Clearance
    • I Gear Position Nose
    • J Gear Position Left
    • K Gear Position Right
    • L Stall Warning
    • R Fuel %
    • W Indicated Air Speed
    • >O Inner Marker
    • >P Middle Marker
    • >Q Outer Marker
    • >R Nav 1 Sound
    • >S Nav 2 Sound
    • >T DME Sound
    • >U ADF 0 Sound
    • >W Marker Sound
    • >X Comm 1 Sound
    • >Y Comm 2 Sound
    • >Z Comm All Sound
    • >a Fuel Gallons Left
    • >c Fuel Gallons Right
    • >g Throttle 1 Position
    • >h Throttle 2 Position
    • >x Flap Handle Position
    • >y Buss Voltage
    • =E Eng 1 Oil Pressure
    • =F Eng 2 Oil Pressure
    • =M Vacuum
    • =T Avionics Buss Volts
    • =V Number of Engines
    • =W Retractable Gear


    My first arrangement used the same framework as many of the examples I've seen where you read the first character from Link2FS and use a series of if statements to pick up on the Extraction Letter and a nested if to deal with the ">" and "=" then perform the appropriate number of reads to assemble the extraction value and act on it.

    When that started to freeze up I attempted a second arrangement that I think I like better since it takes quite a few less lines of code, but it too freezes under the same circumstances noted above. In this arrangement I read the first character and use an if, else if, else if series that uses the ASCII value of the Extraction Letter or Symbol and Letter to create a case number. I then use a when loop to read the balance of the extracted value. A Switch Case follows with a series of cases, one for each extraction.

    Arrangement 1

    Code:
    /*const int LowVolt_M_Anc = 7;  // Declared the pin assignments of all my LEDs and Switches
    // etc.
    
    
    int j1;  // Declared all my integer variables, some with initial values
    // etc.
    
    
    String   // Declared all my String variables, some with initial values
    // etc. 
    
    unsigned long   // Declared all my timer variables variables, some with initial values
    // etc.
    
    
    void setup()
    {
      pinMode(AncBprSlnc, INPUT);
      pinMode(LowVolt_M_Anc,OUTPUT);  // Setup all my I/O pins
    // etc.
    
    
      Serial.begin(9600);
    }
    
    
    void loop()
    {
      j1 = getChar();
    
    
      //------------ AGL <1500 for Gear Up Warning ------------  
      if (j1 == 'D'){
        AGL = "";
        AGL += getChar(); 
        AGL += getChar(); 
        AGL += getChar(); 
        AGL += getChar(); 
        AGL += getChar(); 
        if (AGL != AGLOld){ 
          char carray[6]; 
          AGL.toCharArray(carray, sizeof(carray)); 
          int n = atoi(carray);
          if (n <= 1500) {
            GrAGLWrn = "WRN";
          }
          else{
            GrAGLWrn = "OK";
          } 
        }
        AGLOld = AGL;
      } // End AGL
    
    // A series of similar If Statements to read and act on each extraction.
    
    } // End Program Loop
    
    char getChar()  // Serial Read Function from Zulu Cat
    {
      while(Serial.available() == 0);
      return((char)Serial.read());
    }

    Arrangement 2

    Code:
    /*
    // This one has the same basic Variables Declarations and Setup loop as the first but the main program loop looks like this
    
    
    void loop()
    {
      ExtFlg = getChar();                    // Read next charachter from Link2FS 
      if(ExtFlg > 60 && ExtFlg < 123){ // Check if it is a Letter, ">" or "="
        if(ExtFlg == '>'){                    // If it is ">"
          ExtFlg = getChar();               // Extract next character and
          ExtFlg = ExtFlg + 2000;         // Add 2000 to create Case number
        }
        else if(ExtFlg == '='){     // If it is "="
          ExtFlg = getChar();       // Extract next character and
          ExtFlg = ExtFlg + 3000; // Add 3000 to create Case number
        }
        else{
          ExtFlg = ExtFlg + 1000; // Else Add 1000 to create Case number
        }
      }
    
    
      ExtString = "";         // Clear Extraction String Variable
      ExtVal = getChar();  // Extract next character 
    
    /*
    Run the While Loop to extract all numeric data
    and exit the loop when the ending "," is received.  
    */
    
      while(ExtVal > 42 && ExtVal < 58 && ExtVal != 44){ 
        ExtString += char(ExtVal);
        ExtVal = getChar();
      }
    
    
      switch (ExtFlg) { // Run the case indicated by the extraction flag
    
    
      case 1068:                                                   // D - AGL 
        ExtFlg = 0;                                                 //Clear ExtFlg for start of next Extraction
        if (ExtString != AGL_Last){                           // Check to see if Extracted Value has changed since last read
          char carray[6];                                          // Convert String to numeric value
          ExtString.toCharArray(carray, sizeof(carray)); 
          int n = atoi(carray);
          if (n <= 1500) { 
            GrAGLWrn = "WRN";
          }
          else{
            GrAGLWrn = "OK";
          } 
        }
        AGL_Last = ExtString;
        break; // End AGL
    
    
    
    // Followed by a series of similar cases to read and act on each extraction.
      } // End Switch Case
    
    } // End Program Loop
    
    char getChar()  // Serial Read Function from Zulu Cat
    {
      while(Serial.available() == 0);
      return((char)Serial.read());
    }
    If anybody has any ideas they would be greatly appreciated!
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  2. #2
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Tom this serial buffer thing has come up before so have a look-see at this ,,,
    http://www.mycockpit.org/forums/ardu...rial-port.html
    (I'll make it a sticky as this problem will keep popping up)

    but probably an easier to read version is here ,,,
    http://www.jimspage.co.nz/serial_buffer_mod.htm

    A "Lock up" wouldn't?? be caused by the rec. buffer being full tho so it's probably your PDE code.
    I haven't studied your PDE as we have visitors staying here at the moment ,, plus ,, I'm no expert on PDE's.
    Hopefully one of the other Guys will pop in and help with that side.

    OK back to it Tom ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  3. #3
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Tom,

    I didn't spot anything in the code snippets you posted that would cause the code to hang, but I did notice this:

    Code:
       ExtFlg = ExtFlg + 2000;         // Add 2000 to create Case number
       ExtFlg = ExtFlg + 3000; // Add 3000 to create Case number
       ExtFlg = ExtFlg + 1000; // Else Add 1000 to create Case number
    I assume that you have defined ExtFlg as a "char". That means that its an 8-bit variable and can only hold a value in the range of +127 to -128.

    Also, I wouldn't mind taking a look at ALL the code (not just snippets). If you should choose to share your code it would make it easier for me if you would create a ZIP file with the code in it and then attach the ZIP file to a post here in this thread.

    Best Wishes - Doug

  4. #4
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Jim, Thanks I had made that change to the serial buffer values when I loaded 1.02, but forgot about it when I got the Mega and also updated to 1.03. I pushed those values up and it too care of the freeze ups with rapid altitude changes but I'm still getting freezes if I check off all three gear extractions and cycle the gear.

    Doug, Thanks, I'll post the code I am currently testing before I hit the rack for the night. I just got back in and have a couple tweaks and tests to do then I'll post it.
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  5. #5
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Doug,

    The code is in the code window below and in the attached zip file.

    Thank!!!
    Tom G.

    Code:
    /* Aircradt Annunciator Panel for FSX GA Aircraft
     (also includes misc other indicators) 
     Written by: Tom Gauvin
     interface to FSX via Link2FS V4 www.jimspage.co.nz
    */
    
    
    const int StallHorn = 2;       // Stall Warning Horn
    const int AncBpr = 3;          // Audible Beeper for annunciator alarms *
    const int AncBprSlnc = 50;     // Mute Switch for Audible Beeper
    const int M_Bus_Volt_Rly = 22; // * Relay driver for Master Bus Voltage preent
    const int A_Bus_Volt_Rly = 23; // ** Relay driver for Avionics Bus Voltage preent
    const int HOBBS_Rly = 24;      // Relay driver for Hobbs Meter
    const int AUX_Rly = 25;        // Relay driver TBD
    const int LowVolt_M_Anc = 26;  // Low Master Bus Voltage Annunciator *
    const int LowFuel_L_Anc = 37;  // Low Fuel Annunciator Left Tank *
    const int LowFuel_R_Anc = 34;  // Low Fuel Annunciator Right Tank *
    const int LowOilPrsr_Anc = 27; // Low Oil Pressure Annunciator *
    const int LowVacPrsr_Anc = 28; // Low Vaccuum Anninciator *
    const int GrUpWrn_Anc = 29;    // Gear UP Warning indicator *
    const int GrTrnst_Anc = 30;    // Gear in transit LED *
    const int GrLk_N_Anc = 31;     // Gear Locked Down Nose *
    const int GrLk_L_Anc = 32;     // Gear Locked Down Left *
    const int GrLk_R_Anc = 33;     // Gear Locked Down Right *
    const int Mrk_O_Anc = 38;      // Outer Marker LED **
    const int Mrk_M_Anc = 39;      // Middle Marker LED **
    const int Mrk_I_Anc = 36;      // Inner Marker LED **
    const int Comm_1A_LED = 40;    // Audio Panel Comm 1 LED ** 
    const int Comm_2A_LED = 41;    // Audio Panel Comm 2 LED **
    const int Comm_BA_LED = 42;    // Audio Panel Comm All LED **
    const int Nav_1A_LED = 43;     // Audio Panel Nav 1 LED **
    const int Nav_2A_LED = 44;     // Audio Panel Nav 2 LED **
    const int MKR_A_LED = 45;      // Audio Panel Marker LED **
    const int DME_A_LED = 46;      // Audio Panel DME LED **
    const int ADF_A_LED = 47;      // Audio Panel ADF LED **
    const int FlshPinDflt = 53;    // Default pin assignment for LED Flasher
    // * Cathodes tide common to ground via relay so the LEDs only work if Master Bus Voltage is present 
    // ** Cathodes tide common to ground via relay so the LEDs only work if Avionics Bus Voltage is present 
    
    
    int ExtFlg;                    // Link2FS Extraction designator
    int ExtVal;                    // First Extrated ASCII Character from Link2FS After Designator
    int Fuel_Init = 2;             // Flag to perform Initial Fuel Capacity calculation
    int FuelGal_L, FuelGal_L_Last; // Left Tank Current and Last Extraction
    int FuelGal_R, FuelGal_R_Last; // Right Tank Current and Last Extraction
    int FuelLvl, FuelLvl_Last;     // % Fuel Current and Last Extraction
    int FuelLCap_Clc;              // Calculated per tank fuel capcity
    int AncSlncState;              // Beeper Mute Switch State (High/Low)
    
    
    String ExtString;                              // Extracted Character String from Link2FS
    String EngCnt;                                 // Number of Engines
    String AncBprEnb = "Yes", FlshEnb = "Yes";     // Annunciator Beeper and LED Flasher Enabled State
    String M_Bus_Volt_Last, A_Bus_Volt_Last;       // Last Master & Avionics Bus Voltage Extraction 
    String Stall_Last;                             // Last Stall Warning Extraction
    String AGL_Last;                               // Last Altitude AGL Extraction
    String IAS_Last;                               // Last Indicated Airspeed Extraction
    String Thtl_1_Last, Thtl_2_Last;               // Last Throttle 1 & 2 Extractions
    String GrThtlWrn_1 = "OK", GrThtlWrn_2 = "OK"; // Throttle Flags for Gear Up Warning Logic
    String GrAGLWrn = "OK", GrRtrct;               // Low Altd Warning and Retractable Gear Flag
    String GrIASWrn = "OK", GrFlpWrn = "OK";       // Low Airspeed  and Full Extended Flaps for Gear Up Warning
    String GrUp_N, GrUp_L, GrUp_R;                 // Gear Not Locked Down Flags
    String FlpHndPsn_Last;                         // Last Flap Handle Position Extraction
    String Mrk_O_Last;                             // Last Outer Marker Extraction
    String Mrk_M_Last;                             // Last Middle Marker Extraction
    String Mrk_I_Last;                             // Last Inner Marker Extraction
    String GrPos_N_Last, GrPos_N_Trnst;            // Last Gear Position Extraxtion and Transit State, Nose Gear
    String GrPos_L_Last, GrPos_L_Trnst;            // Last Gear Position Extraxtion and Transit State, Left Gear
    String GrPos_R_Last, GrPos_R_Trnst;            // Last Gear Position Extraxtion and Transit State, Right Gear
    String OilPrsr_1_Last, OilPrsr_2_Last;         // Last Oil Preassure Extractions Engines 1 and 2
    String VacPrsr_Last;                           // Last Vacuum Preassure Extraction
    String Comm_1A_Last, Comm_2A_Last;             // Last Comm Audio Select Extraction 
    String Comm_BA_Last, Nav_1A_Last;              // Last Comm & Nav Audio Select Extraction
    String Nav_2A_Last, MKR_A_Last;                // Last Nav & Marker Audio Select Extraction
    String DME_A_Last, ADF_A_Last;                 // Last DME & ADF Audio Select Extraction
    String Low_Fuel_L_Alm = "Off";                 // State of Low Fuel Left Annunciator Alarm
    String Low_Fuel_R_Alm = "Off";                 // State of Low Fuel Right Annunciator Alarm
    String Gear_Up_Alm = "Off";                    // State of Gear Up Annunciator Alarm
    String Low_Vac_Alm = "Off";                    // State of Low Vacuum Annunciator Alarm
    String Low_Oil_1_Alm = "Off";                  // State of Low Oil Pressure Eng 1 Annunciator Alarm
    String Low_Oil_2_Alm = "Off";                  // State of Low Oil Pressure Eng 2 Annunciator Alarm
    String Low_Volt_Alm = "Off";                   // State of Low Bus Voltage Annunciator Alarm
    
    
    unsigned long CTM_B =millis(), INT_B = 10000; // Audible Beeper 60 Second Mute current time and interval
    // << On final version change RTMINT to 1 minute >>
    unsigned long ETM_B = millis() - INT_B;       // Audible Beeper 60 Second Mute event time
    unsigned long CTM_F =millis(), INT_F = 250;   // Generic LED Flasher current time and interval
    unsigned long ETM_F = millis() - INT_F;       // Generic LED Flasher event time
    
    
    
    
    void setup()
    {
      pinMode(M_Bus_Volt_Rly, OUTPUT);  // Relay Control for * LED Cathode Common & Beeper
      pinMode(A_Bus_Volt_Rly, OUTPUT);  // Relay Control for ** LED Cathode Common
      pinMode(HOBBS_Rly, OUTPUT);       // Relay Control for HOBBS Meter Activation
      pinMode(AUX_Rly, OUTPUT);         // Relay Control for TBD
      pinMode(AncBprSlnc, INPUT);       // Momentary Switch
      pinMode(StallHorn, OUTPUT);       // Piezo Beeper
      pinMode(AncBpr, OUTPUT);          // Piezo Beeper *
      pinMode(LowVolt_M_Anc,OUTPUT);    // LED *
      pinMode(LowFuel_L_Anc, OUTPUT);   // LED *
      pinMode(LowFuel_R_Anc, OUTPUT);   // LED *
      pinMode(LowOilPrsr_Anc, OUTPUT);  // LED *
      pinMode(LowVacPrsr_Anc, OUTPUT);  // LED *
      pinMode(GrUpWrn_Anc, OUTPUT);     // LED *
      pinMode(GrTrnst_Anc, OUTPUT);     // LED *
      pinMode(GrLk_N_Anc, OUTPUT);      // LED *
      pinMode(GrLk_L_Anc, OUTPUT);      // LED *
      pinMode(GrLk_R_Anc, OUTPUT);      // LED *
      pinMode(Mrk_O_Anc, OUTPUT);       // LED **
      pinMode(Mrk_M_Anc, OUTPUT);       // LED **
      pinMode(Mrk_I_Anc, OUTPUT);       // LED **
      pinMode(Comm_1A_LED,OUTPUT);      // LED **
      pinMode(Comm_2A_LED, OUTPUT);     // LED **
      pinMode(Comm_BA_LED, OUTPUT);     // LED **
      pinMode(Nav_1A_LED, OUTPUT);      // LED **
      pinMode(Nav_2A_LED, OUTPUT);      // LED **
      pinMode(MKR_A_LED, OUTPUT);       // LED **
      pinMode(DME_A_LED, OUTPUT);       // LED **
      pinMode(ADF_A_LED, OUTPUT);       // LED **
      pinMode(FlshPinDflt, OUTPUT);     // LED
    
    
      Serial.begin(14400);
    }
    
    
    void loop()
    {
      ExtFlg = getChar();              // Read next charachter from Link2FS
    
    
      if(ExtFlg > 60 && ExtFlg < 123){ // Check if it is a Letter, ">" or "="
        if(ExtFlg == '>'){             // If it is ">"
          ExtFlg = getChar();          // Extract next character and
          ExtFlg = ExtFlg + 2000;      // Add 2000 to create Case number
        }
        else if(ExtFlg == '='){   // If it is "="
          ExtFlg = getChar();     // Extract next character and
          ExtFlg = ExtFlg + 3000; // Add 3000 to create Case number
        }
        else{
          ExtFlg = ExtFlg + 1000; // Else Add 1000 to create Case number
        }
      }
    
    
      ExtString = "";      // Clear Extracttion String Variable
      ExtVal = getChar();  // Extract next character
     
    /*
    Run the While Loop to extract all numeric data
    and exit the loop when the ending "," is received.  
    */
    
    
      while(ExtVal > 42 && ExtVal < 58 && ExtVal != 44){ 
        ExtString += char(ExtVal);
        ExtVal = getChar();
        delay(11);
      }
    
    
      switch (ExtFlg) { // Run the case indicated by the extraction flag
    
    
      case 1068: // D - AGL (used for Gear Up Warning logic)
        ExtFlg = 0;                 //Clear ExtFlg for start of next Extraction
        if (ExtString != AGL_Last){ // Check to see if Extracted Value has changed since last read
          char carray[6];           // Convert String to numeric value
          ExtString.toCharArray(carray, sizeof(carray)); 
          int n = atoi(carray);
          if (n <= 1500) { 
            GrAGLWrn = "WRN";
          }
          else{
            GrAGLWrn = "OK";
          } 
        }
        AGL_Last = ExtString;
        ExtString = "";
        break; // End AGL
    
    
      case 1073: // I - Gear Position Nose
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_N_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_N_Anc, LOW);
            GrUp_N = "WRN";
            GrPos_N_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_N_Anc, HIGH);
            GrUp_N = "OK";
            GrPos_N_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_N_Anc, LOW);
            GrUp_N = "WRN";
            GrPos_N_Trnst = "Yes";
          }
        }
        GrPos_N_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1074: // J - Gear Position Left
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_L_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_L_Anc, LOW);
            GrUp_L = "WRN";
            GrPos_L_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_L_Anc, HIGH);
            GrUp_L = "OK";
            GrPos_L_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_L_Anc, LOW);
            GrUp_L = "WRN";
            GrPos_L_Trnst = "Yes";
          }
        }
        GrPos_L_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1075: // K - Gear Position Right
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_R_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_R_Anc, LOW);
            GrUp_R = "WRN";
            GrPos_R_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_R_Anc, HIGH);
            GrUp_R = "OK";
            GrPos_R_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_R_Anc, LOW);
            GrUp_R = "WRN";
            GrPos_R_Trnst = "Yes";
          }
        }
        GrPos_R_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1076: // L - Stall Warning
        ExtFlg = 0;
        if (ExtString == "1"){
          if (ExtString == Stall_Last){
            analogWrite(StallHorn, 180);
          }
          else {
            for (int SWT = 1; SWT <= 180; SWT++){
              analogWrite(StallHorn, SWT);
              delay(15);
            }
          }  
        }
        if (ExtString == "0"){
          if (ExtString != Stall_Last){
            for (int SWT = 180; SWT >= 0; SWT = SWT - 2){
              analogWrite(StallHorn, SWT);
              delay(10);
            }
          }
        }
        Stall_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 1082: // R - Fuel %
        ExtFlg = 0;
        char carrayFLV[4];
        ExtString.toCharArray(carrayFLV, sizeof(carrayFLV)); 
        FuelLvl = atoi(carrayFLV);
        ExtString = "";
        break;
    
    
      case 1087: // W - Air Speed Indicated 
        ExtFlg = 0;
        if (ExtString != IAS_Last){
          char carrayIAS[5];
          ExtString.toCharArray(carrayIAS, sizeof(carrayIAS)); 
          int n = atoi(carrayIAS);
          if (n < 80){
            GrIASWrn = "WRN";
          }
          else{
            GrIASWrn = "OK";
          } 
          IAS_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 2079: // >O - Inner Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_I_Last){
          digitalWrite(Mrk_I_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_I_Last){
          digitalWrite(Mrk_I_Anc, LOW);
        }
        Mrk_I_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2080: // >P - Middle Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_M_Last){
          digitalWrite(Mrk_M_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_M_Last){
          digitalWrite(Mrk_M_Anc, LOW);
        }
        Mrk_M_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2081: // >Q - Outer Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_O_Last){
          digitalWrite(Mrk_O_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_O_Last){
          digitalWrite(Mrk_O_Anc, LOW);
        }
        Mrk_O_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2082: // >R Nav 1 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Nav_1A_Last){
        }
        else if (ExtString == "0" && ExtString != Nav_1A_Last){
        }
        Nav_1A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2083: // >S Nav 2 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Nav_2A_Last){
        }
        else if (ExtString == "0" && ExtString != Nav_2A_Last){
        }
        Nav_2A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2084: // >T DME Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != DME_A_Last){
        }
        else if (ExtString == "0" && ExtString != DME_A_Last){
        }
        DME_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2085: // >U ADF Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != ADF_A_Last){
        }
        else if (ExtString == "0" && ExtString != ADF_A_Last){
        }
        ADF_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2087: // >W MKR Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != MKR_A_Last){
        }
        else if (ExtString == "0" && ExtString != MKR_A_Last){
        }
        MKR_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2088: // >X - Comm 1 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_1A_Last){
        }
        else if (ExtString == "0" && ExtString != Comm_1A_Last){
        }
        Comm_1A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2089: // >Y - Comm 2 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_2A_Last){
        }
        else if (ExtString == "0" && ExtString != Comm_2A_Last){
        }
        Comm_2A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2090: // >Z - Comm Both Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_BA_Last){
        }
        else if (ExtString == "0" && ExtString != Comm_BA_Last){
        }
        Comm_BA_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2097: // >a - Fuel Gallons left tank
        ExtFlg = 0;
        char carrayFGL[5];
        ExtString.toCharArray(carrayFGL, sizeof(carrayFGL)); 
        FuelGal_L = atoi(carrayFGL);
        ExtString = "";
        break;
    
    
      case 2099: // >c - Fuel Gallons Right tank
        ExtFlg = 0;
        char carrayFGR[5];
        ExtString.toCharArray(carrayFGR, sizeof(carrayFGR)); 
        FuelGal_R = atoi(carrayFGR);
        ExtString = "";
        break;
    
    
      case 2103: // >g - Throttle Position 1 (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString != Thtl_1_Last){
          char carrayT1[5]; 
          ExtString.toCharArray(carrayT1, sizeof(carrayT1)); 
          int n = atoi(carrayT1);
          if (n <= 45) {
            GrThtlWrn_1 = "WRN";
          }
          else{
            GrThtlWrn_1 = "OK";
          } 
        }
        Thtl_1_Last = ExtString;
        ExtString = "";
        break; //End Throttle 1
    
    
      case 2104: // >h - Throttle Position 2 (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString != Thtl_2_Last){
          char carrayT2[5]; 
          ExtString.toCharArray(carrayT2, sizeof(carrayT2)); 
          int n = atoi(carrayT2);
          if (EngCnt == "2" && n <= 45) {
            GrThtlWrn_2 = "WRN";
          }
          else{
            GrThtlWrn_2 = "OK";
          } 
        }
        Thtl_2_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2120: // >x - Flap Handle (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString =="100"){
          GrFlpWrn = "WRN";
        }
        else if (ExtString !="100"){  
          GrFlpWrn = "OK";
        }
        FlpHndPsn_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2121: // >y - Bus Voltage
        ExtFlg = 0;
        if (ExtString != M_Bus_Volt_Last){
          char carrayMBV[5];
          ExtString.toCharArray(carrayMBV, sizeof(carrayMBV)); 
          float n = atoi(carrayMBV);
          if (n < 24){
            Low_Volt_Alm = "On";
            digitalWrite(LowVolt_M_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Volt_Alm = "Off";
            digitalWrite(LowVolt_M_Anc, LOW);
            ANCBeeper("Off");
          }
          if(n < 18){
            digitalWrite(M_Bus_Volt_Rly, HIGH);
            digitalWrite(HOBBS_Rly, LOW);
          }
          else{
            digitalWrite(M_Bus_Volt_Rly, LOW);
            digitalWrite(HOBBS_Rly, HIGH);
          }
          M_Bus_Volt_Last = ExtString;
          ExtString = "";
        }
        break; // End Master Bus Voltage
    
    
      case 3069: // =E - Eng 1 oil pressure
        ExtFlg = 0;
        if (ExtString != OilPrsr_1_Last){
          char carrayOP1[4];
          ExtString.toCharArray(carrayOP1, sizeof(carrayOP1)); 
          int n = atoi(carrayOP1);
          if (n <= 26){
            Low_Oil_1_Alm = "On";
            digitalWrite(LowOilPrsr_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Oil_1_Alm = "Off";
            digitalWrite(LowOilPrsr_Anc, LOW);
            ANCBeeper("Off");
          } 
          OilPrsr_1_Last =ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3070: // =F - Eng 2 oil pressure
        ExtFlg = 0;
        if (ExtString != OilPrsr_2_Last){
          char carrayOP2[4];
          ExtString.toCharArray(carrayOP2, sizeof(carrayOP2)); 
          int n = atoi(carrayOP2);
          if (EngCnt == "2" && n <= 26){
            Low_Oil_2_Alm = "On";
            digitalWrite(LowOilPrsr_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Oil_2_Alm = "Off";
            digitalWrite(LowOilPrsr_Anc, LOW);
            ANCBeeper("Off");
          } 
          OilPrsr_2_Last =ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3077: // =M - Vacuum
        ExtFlg = 0;
        if (ExtString != VacPrsr_Last){
          char carrayV[5];
          ExtString.toCharArray(carrayV, sizeof(carrayV)); 
          float n = atoi(carrayV);
          if (n <= 3.0){
            Low_Vac_Alm = "On";
            digitalWrite(LowVacPrsr_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Vac_Alm = "Off";
            digitalWrite(LowVacPrsr_Anc, LOW);
            ANCBeeper("Off");
          } 
          VacPrsr_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3084: // =T - Avionics Buss Voltage
        ExtFlg = 0;
        if (ExtString != A_Bus_Volt_Last){
          char carrayABV[5];
          ExtString.toCharArray(carrayABV, sizeof(carrayABV)); 
          float n = atoi(carrayABV);
          if(n < 18){
            digitalWrite(A_Bus_Volt_Rly, HIGH);
            digitalWrite(35, HIGH); // TEST LED
          } 
          else{
            digitalWrite(A_Bus_Volt_Rly, LOW);
            digitalWrite(35, LOW); // TEST LED
          } 
          A_Bus_Volt_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3086: // =V - Number of Engines
        ExtFlg = 0;
        EngCnt = ExtString;
        ExtString = "";
        break;
    
    
      case 3087: // =W - Retractable Gear
        ExtFlg = 0;
        GrRtrct = ExtString; 
        ExtString = "";
        break;
    
    
      default:
        ExtFlg = 0;
        ExtString = "";
        break;
      } // END SWITCH CASE
      
    // Gear In Transit Annunciator (if any gear are not locked down or fully retracted)
      if (GrRtrct == "1" && (GrPos_N_Trnst == "Yes" || GrPos_L_Trnst == "Yes" || GrPos_R_Trnst == "Yes")){
        digitalWrite(GrTrnst_Anc, HIGH);
      }
      else{
        digitalWrite(GrTrnst_Anc, LOW);
      } // End Gear In Transit Annunciator
    
    
    //  Gear UP Warning (Gear Not Down & AGL < 1500  & (throttle < 45% or Flaps Full or Air Speed < 90)
      if (GrRtrct == "1" &&
          GrAGLWrn == "WRN" &&
          (GrUp_N == "WRN" || GrUp_L == "WRN" || GrUp_R == "WRN") &&
          (GrThtlWrn_1 == "WRN" || GrThtlWrn_2 == "WRN" || GrIASWrn == "WRN" || GrFlpWrn == "WRN")){
         ANCBeeper("On");
         Gear_Up_Alm = "On";
         digitalWrite(GrUpWrn_Anc, HIGH);
      }
      else{
        Gear_Up_Alm = "Off";
        ANCBeeper("Off");
        digitalWrite(GrUpWrn_Anc, LOW);
      } // End Gear Up Warning
    
    
      //------------ Low Fuel Annunciators ------------
      // Calculate Per tank capacity then alarm per tank if either goes below 25% capcity.
      // Up'd it to 2 cycles.  May take it back down to 1 ???
      if(Fuel_Init > 0 && FuelGal_L > 0 && FuelGal_R > 0 && FuelLvl > 0){
        FuelLCap_Clc = ((FuelGal_L + FuelGal_R) * 100 / FuelLvl) / 2;
        if(Fuel_Init > 0){
          Fuel_Init = Fuel_Init - 1;
        }
        FuelGal_L_Last = FuelGal_L;
        FuelGal_R_Last = FuelGal_R;
        FuelLvl_Last = FuelLvl;
      }
    
    
      if(FuelGal_L < FuelGal_L_Last && FuelGal_L <= (FuelLCap_Clc * 0.25)){
        Low_Fuel_L_Alm = "On";
        digitalWrite(LowFuel_L_Anc, HIGH);
        ANCBeeper("On");
        FuelGal_L_Last = FuelGal_L;
      }
      else if(FuelGal_L > (FuelLCap_Clc * 0.25)){
        Low_Fuel_L_Alm = "Off";
        digitalWrite(LowFuel_L_Anc, LOW);
        ANCBeeper("Off");
        FuelGal_L_Last = FuelGal_L;
      }  
    
    
      if(FuelGal_R < FuelGal_R_Last && FuelGal_R <= (FuelLCap_Clc * 0.25)){
        Low_Fuel_R_Alm = "On";
        digitalWrite(LowFuel_R_Anc, HIGH);
        ANCBeeper("On");
        FuelGal_R_Last = FuelGal_R;
      }
      else if(FuelGal_R > (FuelLCap_Clc * 0.25)){
        Low_Fuel_R_Alm = "Off";
        digitalWrite(LowFuel_R_Anc, LOW);
        ANCBeeper("Off");
        FuelGal_R_Last = FuelGal_R;
      }  
    
    
      if(FuelLvl > FuelLvl_Last){
        Fuel_Init = 2;
      }
    
    
      // End Low Fuel Annunciators 
    
    
      //------------ Annunciator Beeper Silencer, 60 second mute ------------
      AncSlncState = digitalRead(AncBprSlnc);// Annunciator Silencing Function  
      delay(11);
      if (AncSlncState == HIGH) {
        ETM_B = millis();
        ANCBeeper("Mute");
        AncBprEnb = "No";
        //FlshEnb = "No";
      }
      CTM_B = millis();
      if (CTM_B - ETM_B > INT_B){
        AncBprEnb = "Yes";
        //FlshEnb = "Yes";
      }
      else{
        AncBprEnb = "No";
        //FlshEnb = "No";
      } // End Annunciator Silencing Function
      
    } // END MAIN LOOP
    
    
    char getChar()
    {
      while(Serial.available() == 0);
      return((char)Serial.read());
    }
    
    
    void ANCBeeper(String x)
    {
      if (AncBprEnb == "Yes" && x == "On"){
        digitalWrite(AncBpr, HIGH);
      }
      else if(x == "Mute"){
        digitalWrite(AncBpr, LOW);
      }
      else if(x == "Off"){
        if(Low_Fuel_L_Alm == "Off" &&
           Low_Fuel_R_Alm == "Off" &&
           Gear_Up_Alm == "Off" &&
           Low_Vac_Alm == "Off" &&
           Low_Oil_1_Alm == "Off" &&
           Low_Oil_2_Alm == "Off" &&
           Low_Volt_Alm == "Off"){
          digitalWrite(AncBpr, LOW);
        }
      }
    }
    
    
    /* ------------------------ PUNCH LIST ------------------------
     x 1.  Add left and right fuel gallons and split low fuel alarm to left and right tank
     x 2.  Add engine 2 throttle and modify gear up warning.
     x 3.  How to handle single verses twin engine???
     x 4.  How to handle fixed verses retractable gear???
     x 5.  If Jim can provide Avionics bus voltage add a common shut off function for that.
       6.  Add tested Servo Code from original file for flap position indicator
       7.  Write code for stepper motors to run:
           A.  Wet Compass
           B.  AP Elevator Trim
       8.  Take another shot at Dougs Blinker code example to see if the above can be adapted to it.
     x 9.  LCD code for clock, voltmeter, etc.
       10. ELT ???  Only need it to blink so may not be worth routing through the Arduino for that???
     x 11. Add Airspeed below x to the gear up warning???
     x 12. Add Falps fully extended to gear up warning???
       13. Add NAV/GPS Annunciator and Comm panel switches.
     x 14. Decide if lamp test needs any code or if it will use an external switch only?  External Switch!
       15. Can a serial read be forced or a code restart be done after a Master Bus Relay sequence????
       16. How to detect thtottle increase during flasher function?  Another good reason to get Doug's Blinker Code working!
     x 17. Can I re-write low fuel routine to do a tank capcity calc one time and then do a separate per tank % calc after that?
         x If so how do I re-calc when fueling up?  Maybe key it off startup conditions???
       18. Can I eliminate the flshpin to default steps ????
     x 19. Need a better way to deal with beeper off logic for gear warning and low fuel.
         x A. what about separate pin outs for each beeper event (Diode isolated and commoned to one beeper)?
         > B. better code logic?
         x C. leave as is with manual mute.
       20. Investigate false triggering
         x A. Why does activating the "R" Fuel % Extraction trigger the IAS indicator even when "W" Air Speed is not checked?
         x B. Why does activating the "=F" Oil Presure Extraction trigger the Vacuum indicator even when the "=M" Vacuum is not checked?
     */
    
    
    /*
    TEST CHECK LIST
     x 1.  AncBprSlnc  (need to put schmit trigger o input)
     x 2.  LowVolt_M_Anc
     x 3.  LowFuel_L_Anc
     x 4.  LowFuel_R_Anc
     x 5.  LowOilPrsr_Anc
     x 6.  LowVacPrsr_Anc
     x 7.  StallHorn
     x 8.  GrUpWrn_Anc
       9.  GrTrnst_Anc
     x 10. GrLk_N_Anc
       11. GrLk_L_Anc
       12. GrLk_R_Anc
       13. AncBpr
     x 14. Mrk_O_Anc
     x 15. Mrk_M_Anc
     x 16. Mrk_I_Anc
     x 17. M_Bus_Volt_Rly
     x 18. A_Bus_Volt_Rly
       19. HOBBS_Rly
       20. LED Flasher Function
     x 21. Beeper Function
    
    
    */
    Attached Files Attached Files
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  6. #6
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Tom,

    I snagged a copy of your code. I'll start looking at it tomorrow. It may take a day or so to go through.

    Doug -

  7. #7
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Doug, Thanks for looking at it!!!

    What I've found with additional testing is that I can check the Nose Gear Position Extraction and all works properly. If I uncheck that and check the Left Gear extraction it some times works other times not, and if uncheck that and try the Right Gear Extraction it freezes right away. At one point I even had the Nose and Left working together but could not replicate that.

    EDIT: PS, In case you notice the gap, the digital writes to turn on/off the comm panel audio lights are not in the code yet since I ran out of dropping resistors and didn't install the LEDs on my bread board yet.

    All else seems to work well.
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  8. #8
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Tom, Your PDE, sketch, INO or what ever it's called now ,, just one word WOW !!!

    I've been doing a bit of thinking on this one and can you try this ,,,,
    Download ,,,
    www.jimspage.co.nz/link2fs_inout_v4b_4tom.zip
    It's only the exe and needs to be put where the one you use is now. (It needs the other files)
    It handles the Com's slightly different.

    Also (importantly) you need to put your baud rate back up to 115200 in your PDE.

    I'll be interested to know if it makes it better or worse.

    Lets know ,,, Jim

    P.S. I haven't studied your PDE as Doug know his stuff in that department Thanks Doug
    Last edited by Jim NZ; 12-29-2012 at 03:02 PM.
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  9. #9
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Tom,

    I looked at the GEAR code & i didn't spot anything wrong. I'll continue looking at the rest of the code & I'll let you know what happens.

    Doug -

  10. #10
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Too Much Data Too Fast???

    Jim,

    Don't know what you did in this new version, but between that and kickig it back up to 115200 things are running much much better! Thanks!!!

    I have all three gear extractions running and have cycled the gear several times and done several rapid ascents and descents with no freezes. I've even cycled the gear several times while doing rapid ascents and descents. With no freezes.

    I do experience some lag in other functions when doing the rapid ascents and descents but I think that's normal. The only other thing I've seen is a couple momentary hick-ups where things like a split second low oil pressure might happen or Low Vac, but that seems to be rare and may still be a result of the way I'm reading the extractions.

    Doug,

    With the success noted above, I decided to take the next step while waiting for your feedback and I added a few more embellishments from my original work to include, additional code comments, my original LED Flasher function (to be replaced later with an improved no delay version), and a few other clean ups. In case it makes a difference I've attached and posted the revised code here.

    Code:
    /* Aircradt Annunciator Panel for FSX GA Aircraft
     (also includes misc other indicators) 
     Written by: Tom Gauvin
     interface to FSX via Link2FS V4 www.jimspage.co.nz
    */
    
    
    const int StallHorn = 2;         // Stall Warning Horn
    const int AncBpr = 3;            // Audible Beeper for annunciator alarms *
    const int AncBprMute = 50;       // Mute Switch for Audible Beeper
    const int M_Bus_Volt_Rly = 22;   // * Relay driver for Master Bus Voltage preent
    const int A_Bus_Volt_Rly = 23;   // ** Relay driver for Avionics Bus Voltage preent
    const int HOBBS_Rly = 24;        // Relay driver for Hobbs Meter
    const int AUX_Rly = 25;          // Relay driver TBD
    const int LowVolt_M_Anc = 26;    // Low Master Bus Voltage Annunciator *
    const int LowFuel_L_Anc = 37;    // Low Fuel Annunciator Left Tank *
    const int LowFuel_R_Anc = 34;    // Low Fuel Annunciator Right Tank *
    const int LowOilPrsr_1_Anc = 27; // Low Oil Pressure Eng 1 Annunciator *
    const int LowOilPrsr_2_Anc = 35; // Low Oil Pressure Eng 2 Annunciator *
    const int LowVacPrsr_Anc = 28;   // Low Vaccuum Anninciator *
    const int GrUpWrn_Anc = 29;      // Gear UP Warning indicator *
    const int GrTrnst_Anc = 30;      // Gear in transit LED *
    const int GrLk_N_Anc = 31;       // Gear Locked Down Nose *
    const int GrLk_L_Anc = 32;       // Gear Locked Down Left *
    const int GrLk_R_Anc = 33;       // Gear Locked Down Right *
    const int Mrk_O_Anc = 38;        // Outer Marker LED **
    const int Mrk_M_Anc = 39;        // Middle Marker LED **
    const int Mrk_I_Anc = 36;        // Inner Marker LED **
    const int Comm_1A_LED = 40;      // Audio Panel Comm 1 LED ** 
    const int Comm_2A_LED = 41;      // Audio Panel Comm 2 LED **
    const int Comm_BA_LED = 42;      // Audio Panel Comm All LED **
    const int Nav_1A_LED = 43;       // Audio Panel Nav 1 LED **
    const int Nav_2A_LED = 44;       // Audio Panel Nav 2 LED **
    const int MKR_A_LED = 45;        // Audio Panel Marker LED **
    const int DME_A_LED = 46;        // Audio Panel DME LED **
    const int ADF_A_LED = 47;        // Audio Panel ADF LED **
    const int FlshPinDflt = 53;      // Default pin assignment for LED Flasher
    // * Cathodes tide common to ground via relay so the LEDs only work if Master Bus Voltage is present 
    // ** Cathodes tide common to ground via relay so the LEDs only work if Avionics Bus Voltage is present 
    
    
    int ExtFlg;                        // Link2FS Extraction designator
    int ExtVal;                        // First Extrated ASCII Character from Link2FS After Designator
    int Fuel_Init = 2;                 // Flag to perform Initial Fuel Capacity calculation
    int FuelGal_L, FuelGal_L_Last;     // Left Tank Current and Last Extraction
    int FuelGal_R, FuelGal_R_Last;     // Right Tank Current and Last Extraction
    int FuelLvl, FuelLvl_Last;         // % Fuel Current and Last Extraction
    int FuelLCap_Clc;                  // Calculated per tank fuel capcity
    int AncMuteState;                  // Beeper Mute Switch State (High/Low)
    int FlshFlgF, FlshCntF = 20;       // Annunciator Flasher State
    int FlshPin = FlshPinDflt;         // Annunciator Flash Count, and LED Pin assignment
    
    
    String ExtString;                              // Extracted Character String from Link2FS
    String EngCnt;                                 // Number of Engines
    String AncBprEnb = "Yes", FlshEnb = "Yes";     // Annunciator Beeper and LED Flasher Enabled State
    String M_Bus_Volt_Last, A_Bus_Volt_Last;       // Last Master & Avionics Bus Voltage Extraction 
    String Stall_Last;                             // Last Stall Warning Extraction
    String AGL_Last;                               // Last Altitude AGL Extraction
    String IAS_Last;                               // Last Indicated Airspeed Extraction
    String Thtl_1_Last, Thtl_2_Last;               // Last Throttle 1 & 2 Extractions
    String GrThtlWrn_1 = "OK", GrThtlWrn_2 = "OK"; // Throttle Flags for Gear Up Warning Logic
    String GrAGLWrn = "OK",GrAGLWrn2 = "OK";       // Low Altd Warnings <1500 and <500
    String GrIASWrn = "OK", GrFlpWrn = "OK";       // Low Airspeed  and Full Extended Flaps for Gear Up Warning
    String GrUp_N, GrUp_L, GrUp_R, GrRtrct;        // Gear Not Locked Down Flags, and Retractable Gear Flag
    String FlpHndPsn_Last;                         // Last Flap Handle Position Extraction
    String Mrk_O_Last;                             // Last Outer Marker Extraction
    String Mrk_M_Last;                             // Last Middle Marker Extraction
    String Mrk_I_Last;                             // Last Inner Marker Extraction
    String GrPos_N_Last, GrPos_N_Trnst;            // Last Gear Position Extraxtion and Transit State, Nose Gear
    String GrPos_L_Last, GrPos_L_Trnst;            // Last Gear Position Extraxtion and Transit State, Left Gear
    String GrPos_R_Last, GrPos_R_Trnst;            // Last Gear Position Extraxtion and Transit State, Right Gear
    String OilPrsr_1_Last, OilPrsr_2_Last;         // Last Oil Preassure Extractions Engines 1 and 2
    String VacPrsr_Last;                           // Last Vacuum Preassure Extraction
    String Comm_1A_Last, Comm_2A_Last;             // Last Comm Audio Select Extraction 
    String Comm_BA_Last, Nav_1A_Last;              // Last Comm & Nav Audio Select Extraction
    String Nav_2A_Last, MKR_A_Last;                // Last Nav & Marker Audio Select Extraction
    String DME_A_Last, ADF_A_Last;                 // Last DME & ADF Audio Select Extraction
    String Low_Fuel_L_Alm = "Off";                 // State of Low Fuel Left Annunciator Alarm
    String Low_Fuel_R_Alm = "Off";                 // State of Low Fuel Right Annunciator Alarm
    String Gear_Up_Alm = "Off";                    // State of Gear Up Annunciator Alarm
    String Low_Vac_Alm = "Off";                    // State of Low Vacuum Annunciator Alarm
    String Low_Oil_1_Alm = "Off";                  // State of Low Oil Pressure Eng 1 Annunciator Alarm
    String Low_Oil_2_Alm = "Off";                  // State of Low Oil Pressure Eng 2 Annunciator Alarm
    String Low_Volt_Alm = "Off";                   // State of Low Bus Voltage Annunciator Alarm
    
    
    unsigned long CTM_B =millis(), INT_B = 10000; // Audible Beeper 60 Second Mute current time and interval
                                                  // << On final version change RTMINT to 1 minute >>
    unsigned long ETM_B = millis() - INT_B;       // Audible Beeper 60 Second Mute event time
    unsigned long CTM_F =millis(), INT_F = 250;   // LED Flasher current time and interval
    unsigned long ETM_F = millis() - INT_F;       // LED Flasher event time
    
    
    void setup()
    {
      pinMode(M_Bus_Volt_Rly, OUTPUT);   // Relay Control for * LED Cathode Common & Beeper
      pinMode(A_Bus_Volt_Rly, OUTPUT);   // Relay Control for ** LED Cathode Common
      pinMode(HOBBS_Rly, OUTPUT);        // Relay Control for HOBBS Meter Activation
      pinMode(AUX_Rly, OUTPUT);          // Relay Control for TBD
      pinMode(AncBprMute, INPUT);        // Momentary Switch
      pinMode(StallHorn, OUTPUT);        // Piezo Beeper
      pinMode(AncBpr, OUTPUT);           // Piezo Beeper *
      pinMode(LowVolt_M_Anc,OUTPUT);     // LED *
      pinMode(LowFuel_L_Anc, OUTPUT);    // LED *
      pinMode(LowFuel_R_Anc, OUTPUT);    // LED *
      pinMode(LowOilPrsr_1_Anc, OUTPUT); // LED *
      pinMode(LowOilPrsr_2_Anc, OUTPUT); // LED *
      pinMode(LowVacPrsr_Anc, OUTPUT);   // LED *
      pinMode(GrUpWrn_Anc, OUTPUT);      // LED *
      pinMode(GrTrnst_Anc, OUTPUT);      // LED *
      pinMode(GrLk_N_Anc, OUTPUT);       // LED *
      pinMode(GrLk_L_Anc, OUTPUT);       // LED *
      pinMode(GrLk_R_Anc, OUTPUT);       // LED *
      pinMode(Mrk_O_Anc, OUTPUT);        // LED **
      pinMode(Mrk_M_Anc, OUTPUT);        // LED **
      pinMode(Mrk_I_Anc, OUTPUT);        // LED **
      pinMode(Comm_1A_LED,OUTPUT);       // LED **
      pinMode(Comm_2A_LED, OUTPUT);      // LED **
      pinMode(Comm_BA_LED, OUTPUT);      // LED **
      pinMode(Nav_1A_LED, OUTPUT);       // LED **
      pinMode(Nav_2A_LED, OUTPUT);       // LED **
      pinMode(MKR_A_LED, OUTPUT);        // LED **
      pinMode(DME_A_LED, OUTPUT);        // LED **
      pinMode(ADF_A_LED, OUTPUT);        // LED **
      pinMode(FlshPinDflt, OUTPUT);      // LED
    
    
      Serial.begin(115200);
    
    
    }
    
    
    void loop()
    {
      ExtFlg = getChar();              // Read next charachter from Link2FS
    
    
      if(ExtFlg > 60 && ExtFlg < 123){ // Check if it is a Letter, ">" or "="
        if(ExtFlg == '>'){             // If it is ">"
          ExtFlg = getChar();          // Extract next character and
          ExtFlg = ExtFlg + 2000;      // Add 2000 to create Case number
        }
        else if(ExtFlg == '='){        // If it is "="
          ExtFlg = getChar();          // Extract next character and
          ExtFlg = ExtFlg + 3000;      // Add 3000 to create Case number
        }
        else{
          ExtFlg = ExtFlg + 1000;      // Else Add 1000 to create Case number
        }
      }
    
    
      ExtString = "";      // Clear Extracttion String Variable
      ExtVal = getChar();  // Extract next character
    
    
    /*
    Run the While Loop to extract all numeric data
    and exit the loop when the ending "," is received.  
    */
    
    
      while(ExtVal > 42 && ExtVal < 58 && ExtVal != 44){ 
        ExtString += char(ExtVal);
        ExtVal = getChar();
        delay(11);
      }
    
    
      switch (ExtFlg) { // Run the case indicated by the extraction flag
    
    
        case 1068: // D - AGL (used for Gear Up Warning logic)
        ExtFlg = 0;                 //Clear ExtFlg for start of next Extraction
        if (ExtString != AGL_Last){ // Check to see if Extracted Value has changed since last read
          char carray[6];           // Convert String to numeric value
          ExtString.toCharArray(carray, sizeof(carray)); 
          int n = atoi(carray);
          if (n <= 1500) { 
            GrAGLWrn = "WRN";
          }
          else{
            GrAGLWrn = "OK";
          } 
          if (n <= 500) { 
            GrAGLWrn2 = "WRN";
          }
          else{
            GrAGLWrn2 = "OK";
          } 
        }
        AGL_Last = ExtString;
        ExtString = "";
        break; // End AGL
    
    
      case 1073: // I - Gear Position Nose
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_N_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_N_Anc, LOW);
            GrUp_N = "WRN";
            GrPos_N_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_N_Anc, HIGH);
            GrUp_N = "OK";
            GrPos_N_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_N_Anc, LOW);
            GrUp_N = "WRN";
            GrPos_N_Trnst = "Yes";
          }
        }
        GrPos_N_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1074: // J - Gear Position Left
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_L_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_L_Anc, LOW);
            GrUp_L = "WRN";
            GrPos_L_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_L_Anc, HIGH);
            GrUp_L = "OK";
            GrPos_L_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_L_Anc, LOW);
            GrUp_L = "WRN";
            GrPos_L_Trnst = "Yes";
          }
        }
        GrPos_L_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1075: // K - Gear Position Right
        ExtFlg = 0;
    
    
        if (ExtString != GrPos_R_Last){
          if(ExtString == "000" || ExtString == "001"){
            digitalWrite(GrLk_R_Anc, LOW);
            GrUp_R = "WRN";
            GrPos_R_Trnst = "No";
          }
          else if(ExtString == "099" || ExtString == "100"){
            digitalWrite(GrLk_R_Anc, HIGH);
            GrUp_R = "OK";
            GrPos_R_Trnst = "No";
          }
          else{
            digitalWrite(GrLk_R_Anc, LOW);
            GrUp_R = "WRN";
            GrPos_R_Trnst = "Yes";
          }
        }
        GrPos_R_Last = ExtString;
        ExtString = "";
    
    
        break;
    
    
      case 1076: // L - Stall Warning
        ExtFlg = 0;
        if (ExtString == "1"){
          if (ExtString == Stall_Last){
            analogWrite(StallHorn, 180);
          }
          else {
            for (int SWT = 1; SWT <= 180; SWT++){
              analogWrite(StallHorn, SWT);
              delay(15);
            }
          }  
        }
        if (ExtString == "0"){
          if (ExtString != Stall_Last){
            for (int SWT = 180; SWT >= 0; SWT = SWT - 2){
              analogWrite(StallHorn, SWT);
              delay(10);
            }
          }
        }
        Stall_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 1082: // R - Fuel %
        ExtFlg = 0;
        char carrayFLV[4];
        ExtString.toCharArray(carrayFLV, sizeof(carrayFLV)); 
        FuelLvl = atoi(carrayFLV);
        ExtString = "";
        break;
    
    
      case 1087: // W - Air Speed Indicated 
        ExtFlg = 0;
        if (ExtString != IAS_Last){
          char carrayIAS[5];
          ExtString.toCharArray(carrayIAS, sizeof(carrayIAS)); 
          int n = atoi(carrayIAS);
          if (n < 80){
            GrIASWrn = "WRN";
          }
          else{
            GrIASWrn = "OK";
          } 
          IAS_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 2079: // >O - Inner Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_I_Last){
          digitalWrite(Mrk_I_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_I_Last){
          digitalWrite(Mrk_I_Anc, LOW);
        }
        Mrk_I_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2080: // >P - Middle Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_M_Last){
          digitalWrite(Mrk_M_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_M_Last){
          digitalWrite(Mrk_M_Anc, LOW);
        }
        Mrk_M_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2081: // >Q - Outer Marker
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Mrk_O_Last){
          digitalWrite(Mrk_O_Anc, HIGH);
        }
        else if (ExtString == "0" && ExtString != Mrk_O_Last){
          digitalWrite(Mrk_O_Anc, LOW);
        }
        Mrk_O_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2082: // >R Nav 1 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Nav_1A_Last){
          digitalWrite(Nav_1A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != Nav_1A_Last){
          digitalWrite(Nav_1A_LED, LOW);
        }
        Nav_1A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2083: // >S Nav 2 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Nav_2A_Last){
          digitalWrite(Nav_2A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != Nav_2A_Last){
          digitalWrite(Nav_2A_LED, LOW);
        }
        Nav_2A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2084: // >T DME Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != DME_A_Last){
          digitalWrite(DME_A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != DME_A_Last){
          digitalWrite(DME_A_LED, LOW);
        }
        DME_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2085: // >U ADF Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != ADF_A_Last){
          digitalWrite(ADF_A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != ADF_A_Last){
          digitalWrite(ADF_A_LED, LOW);
        }
        ADF_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2087: // >W MKR Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != MKR_A_Last){
          digitalWrite(MKR_A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != MKR_A_Last){
          digitalWrite(MKR_A_LED, LOW);
        }
        MKR_A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2088: // >X - Comm 1 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_1A_Last){
          digitalWrite(Comm_1A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != Comm_1A_Last){
          digitalWrite(Comm_1A_LED, LOW);
        }
        Comm_1A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2089: // >Y - Comm 2 Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_2A_Last){
          digitalWrite(Comm_2A_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != Comm_2A_Last){
          digitalWrite(Comm_2A_LED, LOW);
        }
        Comm_2A_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2090: // >Z - Comm Both Sound
        ExtFlg = 0;
        if (ExtString == "1" && ExtString != Comm_BA_Last){
          digitalWrite(Comm_BA_LED, HIGH);
        }
        else if (ExtString == "0" && ExtString != Comm_BA_Last){
          digitalWrite(Comm_BA_LED, LOW);
        }
        Comm_BA_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2097: // >a - Fuel Gallons left tank
        ExtFlg = 0;
        char carrayFGL[5];
        ExtString.toCharArray(carrayFGL, sizeof(carrayFGL)); 
        FuelGal_L = atoi(carrayFGL);
        ExtString = "";
        break;
    
    
      case 2099: // >c - Fuel Gallons Right tank
        ExtFlg = 0;
        char carrayFGR[5];
        ExtString.toCharArray(carrayFGR, sizeof(carrayFGR)); 
        FuelGal_R = atoi(carrayFGR);
        ExtString = "";
        break;
    
    
      case 2103: // >g - Throttle Position 1 (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString != Thtl_1_Last){
          char carrayT1[5]; 
          ExtString.toCharArray(carrayT1, sizeof(carrayT1)); 
          int n = atoi(carrayT1);
          if (n <= 45) {
            GrThtlWrn_1 = "WRN";
          }
          else{
            GrThtlWrn_1 = "OK";
          } 
        }
        Thtl_1_Last = ExtString;
        ExtString = "";
        break; //End Throttle 1
    
    
      case 2104: // >h - Throttle Position 2 (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString != Thtl_2_Last){
          char carrayT2[5]; 
          ExtString.toCharArray(carrayT2, sizeof(carrayT2)); 
          int n = atoi(carrayT2);
          if (EngCnt == "2" && n <= 45) {
            GrThtlWrn_2 = "WRN";
          }
          else{
            GrThtlWrn_2 = "OK";
          } 
        }
        Thtl_2_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2120: // >x - Flap Handle (used for Gear Up Warning logic)
        ExtFlg = 0;
        if (ExtString =="100"){
          GrFlpWrn = "WRN";
        }
        else if (ExtString !="100"){  
          GrFlpWrn = "OK";
        }
        FlpHndPsn_Last = ExtString;
        ExtString = "";
        break;
    
    
      case 2121: // >y - Bus Voltage
        ExtFlg = 0;
        if (ExtString != M_Bus_Volt_Last){
          char carrayMBV[5];
          ExtString.toCharArray(carrayMBV, sizeof(carrayMBV)); 
          float n = atoi(carrayMBV);
          if (n < 23){
            Low_Volt_Alm = "On";
            ANCBeeper("On");                        // turn on Audible beeper via Annunciator Beeper function                         
            if (digitalRead(LowVolt_M_Anc) == LOW){ // If LED is not already on then
              FlshPin = LowVolt_M_Anc;              // Set FLasher Function output pin            
              LEDFlash();                           // and execute LED Flasher Function
            }
          }
          else{
            Low_Volt_Alm = "Off";
            digitalWrite(LowVolt_M_Anc, LOW);
            ANCBeeper("Off");                       // turn off Audible beeper via Annunciator Beeper function
          }
          if(n < 18){
            digitalWrite(M_Bus_Volt_Rly, HIGH);     // Energize Relay removing ground from annunciator common cathode bus
            digitalWrite(HOBBS_Rly, LOW);           // De-Energize Relay removing power from Hobbs Meter
          }
          else{
            digitalWrite(M_Bus_Volt_Rly, LOW);      // De-Energize Relay returning ground to annunciator common cathode bus
            digitalWrite(HOBBS_Rly, HIGH);          // Energize Relay and power Hobbs Meter
          }
          M_Bus_Volt_Last = ExtString;
          ExtString = "";
        }
        break; // End Master Bus Voltage
    
    
      case 3069: // =E - Eng 1 oil pressure
        ExtFlg = 0;
        if (ExtString != OilPrsr_1_Last){
          char carrayOP1[4];
          ExtString.toCharArray(carrayOP1, sizeof(carrayOP1)); 
          int n = atoi(carrayOP1);
          if (n <= 26){
            Low_Oil_1_Alm = "On";
            digitalWrite(LowOilPrsr_1_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Oil_1_Alm = "Off";
            digitalWrite(LowOilPrsr_1_Anc, LOW);
            ANCBeeper("Off");
          } 
          OilPrsr_1_Last =ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3070: // =F - Eng 2 oil pressure
        ExtFlg = 0;
        if (ExtString != OilPrsr_2_Last){
          char carrayOP2[4];
          ExtString.toCharArray(carrayOP2, sizeof(carrayOP2)); 
          int n = atoi(carrayOP2);
          if (EngCnt == "2" && n <= 26){
            Low_Oil_2_Alm = "On";
            digitalWrite(LowOilPrsr_2_Anc, HIGH);
            ANCBeeper("On");
          }
          else{
            Low_Oil_2_Alm = "Off";
            digitalWrite(LowOilPrsr_2_Anc, LOW);
            ANCBeeper("Off");
          } 
          OilPrsr_2_Last =ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3077: // =M - Vacuum
        ExtFlg = 0;
        if (ExtString != VacPrsr_Last){
          char carrayV[5];
          ExtString.toCharArray(carrayV, sizeof(carrayV)); 
          float n = atoi(carrayV);
          if (n <= 3.0){
            Low_Vac_Alm = "On";
            ANCBeeper("On");
            if (digitalRead(LowVacPrsr_Anc) == LOW){
              FlshPin = LowVacPrsr_Anc;
              LEDFlash();
            }
          }
          else{
            Low_Vac_Alm = "Off";
            digitalWrite(LowVacPrsr_Anc, LOW);
            ANCBeeper("Off");
          } 
          VacPrsr_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3084: // =T - Avionics Buss Voltage
        ExtFlg = 0;
        if (ExtString != A_Bus_Volt_Last){
          char carrayABV[5];
          ExtString.toCharArray(carrayABV, sizeof(carrayABV)); 
          float n = atoi(carrayABV);
          if(n < 18){
            digitalWrite(A_Bus_Volt_Rly, HIGH); // Energize Relay removing ground from Avionics common cathode bus
          } 
          else{
            digitalWrite(A_Bus_Volt_Rly, LOW);  // De-Energize Relay returning ground to Avionics common cathode bus
          } 
          A_Bus_Volt_Last = ExtString;
          ExtString = "";
        }
        break;
    
    
      case 3086: // =V - Number of Engines
        ExtFlg = 0;
        EngCnt = ExtString;
        ExtString = "";
        break;
    
    
      case 3087: // =W - Retractable Gear
        ExtFlg = 0;
        GrRtrct = ExtString; 
        ExtString = "";
        break;
    
    
      default:
        ExtFlg = 0;
        ExtString = "";
        break;
      } // END SWITCH CASE
    
    
    
    
    // Gear In Transit Annunciator (if any gear are not locked down or fully retracted)
      if (GrRtrct == "1" && (GrPos_N_Trnst == "Yes" || GrPos_L_Trnst == "Yes" || GrPos_R_Trnst == "Yes")){
        digitalWrite(GrTrnst_Anc, HIGH);
      }
      else{
        digitalWrite(GrTrnst_Anc, LOW);
      } // End Gear In Transit Annunciator
    
    
    //  Gear UP Warning (Gear Not Down & AGL < 1500  & (throttle < 45% or Flaps Full or Air Speed < 90)
      if (GrRtrct == "1" &&
        GrAGLWrn == "WRN" &&
        (GrUp_N == "WRN" || GrUp_L == "WRN" || GrUp_R == "WRN") &&
        (GrThtlWrn_1 == "WRN" || GrThtlWrn_2 == "WRN" || GrIASWrn == "WRN" || GrFlpWrn == "WRN" || GrAGLWrn2 == "WRN")){
        Gear_Up_Alm = "On";
        ANCBeeper("On");
        if (digitalRead(GrUpWrn_Anc) == LOW){
          FlshPin = GrUpWrn_Anc;
          LEDFlash();
        }
    
    
      }
      else{
        Gear_Up_Alm = "Off";
        ANCBeeper("Off");
        digitalWrite(GrUpWrn_Anc, LOW);
      } // End Gear Up Warning
    
    
    //------------ Low Fuel Annunciators ------------
      // Calculate Per tank capacity then alarm per tank if either goes below 25% capcity.
      // Added a second pass because sometimes the first pass doesn't calculate properly
      // IF both tank extractions haven't updated yet
    
    
      if(Fuel_Init > 0 && FuelGal_L > 0 && FuelGal_R > 0 && FuelLvl > 0){
        FuelLCap_Clc = ((FuelGal_L + FuelGal_R) * 100 / FuelLvl) / 2;
        if(Fuel_Init > 0){
          Fuel_Init = Fuel_Init - 1;
        }
        FuelGal_L_Last = FuelGal_L;
        FuelGal_R_Last = FuelGal_R;
        FuelLvl_Last = FuelLvl;
    
    
      }
    
    
      if(FuelGal_L < FuelGal_L_Last && FuelGal_L <= (FuelLCap_Clc * 0.25)){
        Low_Fuel_L_Alm = "On";
        FuelGal_L_Last = FuelGal_L;
        ANCBeeper("On");
        if (digitalRead(LowFuel_L_Anc) == LOW){
          FlshPin = LowFuel_L_Anc;
          LEDFlash();
        }
      }
      else if(FuelGal_L > (FuelLCap_Clc * 0.25)){
        Low_Fuel_L_Alm = "Off";
        digitalWrite(LowFuel_L_Anc, LOW);
        ANCBeeper("Off");
        FuelGal_L_Last = FuelGal_L;
      }  
    
    
      if(FuelGal_R < FuelGal_R_Last && FuelGal_R <= (FuelLCap_Clc * 0.25)){
        Low_Fuel_R_Alm = "On";
        FuelGal_R_Last = FuelGal_R;
        ANCBeeper("On");
        if (digitalRead(LowFuel_R_Anc) == LOW){
          FlshPin = LowFuel_R_Anc;
          LEDFlash();
        }
      }
      else if(FuelGal_R > (FuelLCap_Clc * 0.25)){
        Low_Fuel_R_Alm = "Off";
        digitalWrite(LowFuel_R_Anc, LOW);
        ANCBeeper("Off");
        FuelGal_R_Last = FuelGal_R;
      }  
    
    
      if(FuelLvl > FuelLvl_Last){ // If fuel increases (refuel) then recalc tank capacity.
        Fuel_Init = 2;
      }
      // End Low Fuel Annunciators 
    
    
    //------------ Annunciator Beeper, 60 second mute ------------
      AncMuteState = digitalRead(AncBprMute);// Annunciator Mute Function  
      delay(11);
      if (AncMuteState == HIGH) {
        ETM_B = millis();
        ANCBeeper("Mute");
        AncBprEnb = "No";
        FlshEnb = "No";
      }
      CTM_B = millis();
      if (CTM_B - ETM_B > INT_B){
        AncBprEnb = "Yes";
        FlshEnb = "Yes";
      }
      else{
        AncBprEnb = "No";
        FlshEnb = "No";
      } // End Annunciator Silencing Function
    
    
    
    
    } // END MAIN LOOP
    
    
    char getChar()  // Serial Read function form Doug
    {
      while(Serial.available() == 0);
      return((char)Serial.read());
    }
    
    
    void ANCBeeper(String x) // Audible Annunciator On/Off
    {
      if (AncBprEnb == "Yes" && x == "On"){ // Turn on beeper if Beeper Enabled (see mute function above) 
        digitalWrite(AncBpr, HIGH);
      }
      else if(x == "Mute"){                 // Silence beeper regradless of active alarms (see mute function above)
        digitalWrite(AncBpr, LOW);
      }
      else if(x == "Off"){                  // Shut off beeper only if no alarms are active.
        if(Low_Fuel_L_Alm == "Off" &&
          Low_Fuel_R_Alm == "Off" &&
          Gear_Up_Alm == "Off" &&
          Low_Vac_Alm == "Off" &&
          Low_Oil_1_Alm == "Off" &&
          Low_Oil_2_Alm == "Off" &&
          Low_Volt_Alm == "Off"){
          digitalWrite(AncBpr, LOW);
        }
      }
    }
    void LEDFlash()  // Flash the selected LED 20 tiumes then turn it on steady (try to replace with Doug's no delay code)
    {
      while(FlshCntF > 0){
        CTM_F = millis();
        if(CTM_F - ETM_F >= INT_F){
          if(FlshFlgF == 1){
            digitalWrite(FlshPin, HIGH);
          }
          else{
            digitalWrite(FlshPin, LOW);
          }
          FlshFlgF ^= 1;
          FlshCntF--;
          ETM_F = CTM_F;
        }
      }
      digitalWrite(FlshPin, HIGH);
      FlshCntF = 20;
      FlshPin = FlshPinDflt;
    }
    
    
    /* ------------------------ PUNCH LIST ------------------------
     x 1.  Add left and right fuel gallons and split low fuel alarm to left and right tank
     x 2.  Add engine 2 throttle and modify gear up warning.
     x 3.  How to handle single verses twin engine???
     x 4.  How to handle fixed verses retractable gear???
     x 5.  If Jim can provide Avionics bus voltage add a common shut off function for that.
       6.  Add tested Servo Code from original file for flap position indicator
       7.  Write code for stepper motors to run:
           A.  Wet Compass
           B.  AP Elevator Trim
       8.  Take another shot at Dougs Blinker code example to see if the above can be adapted to it.
     x 9.  LCD code for clock, voltmeter, etc.
       10. ELT ???  Only need it to blink so may not be worth routing through the Arduino for that???
     x 11. Add Airspeed below x to the gear up warning???
     x 12. Add Falps fully extended to gear up warning???
       13. Add NAV/GPS Annunciator and Comm panel switches.
     x 14. Decide if lamp test needs any code or if it will use an external switch only?  External Switch!
       15. Can a serial read be forced or a code restart be done after a Master Bus Relay sequence????
       16. How to detect thtottle increase during flasher function?  Another good reason to get Doug's Blinker Code working!
     x 17. Can I re-write low fuel routine to do a tank capcity calc one time and then do a separate per tank % calc after that?
     x If so how do I re-calc when fueling up?  Maybe key it off startup conditions???
       18. Can I eliminate the flshpin to default steps ????
     x 19. Need a better way to deal with beeper off logic for gear warning and low fuel.
     x A. what about separate pin outs for each beeper event (Diode isolated and commoned to one beeper)?
     > B. better code logic?
     x C. leave as is with manual mute.
     x 20. Investigate false triggering
         x A. Why does activating the "R" Fuel % Extraction trigger the IAS indicator even when "W" Air Speed is not checked?
         x B. Why does activating the "=F" Oil Presure Extraction trigger the Vacuum indicator even when the "=M" Vacuum is not checked?
     x 21. Add AGL below 250 to Gear Up Warning
     */
    
    
    /* TEST CHECK LIST
     
     x 1.  AncBprMute  (need to put schmit trigger on input)
     x 2.  LowVolt_M_Anc
     x 3.  LowFuel_L_Anc
     x 4.  LowFuel_R_Anc
     x 5.  LowOilPrsr_Anc
     x 6.  LowVacPrsr_Anc
     x 7.  StallHorn
     x 8.  GrUpWrn_Anc
     x 9.  GrTrnst_Anc
     x 10. GrLk_N_Anc
       11. GrLk_L_Anc
       12. GrLk_R_Anc
     x 13. AncBpr
     x 14. Mrk_O_Anc
     x 15. Mrk_M_Anc
     x 16. Mrk_I_Anc
     x 17. M_Bus_Volt_Rly
     x 18. A_Bus_Volt_Rly
     x 19. HOBBS_Rly
     x 20. LED Flasher Function (see note 8 above)
     x 21. Beeper Function
     
     */
    Attached Files Attached Files
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

Page 1 of 3 123 LastLast