Page 2 of 11 FirstFirst 123456 ... LastLast
Results 11 to 20 of 106
  1. #11
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    236
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    UPDATE PART I:
    Feb. 21, 2015.
    80%ish complete.
    It's been over a year since I conceived this project.
    In that time I have been working on and off sporadically. That's life I guess.
    I have noticed a number of people requesting help with Auto Pilot projects and coding, so I have compiled and formatted what I have so far.
    There are six different ways to skin a cat. This is the way I do it.
    I don't use a Quadrature Library and I have come up with my own Acceleration for Encoders.
    Read the Remarks, I tried to give complete instruction, at least for the top half.

    Here is the first half of the code. It's too big to post whole.
    This section contains all of the Code except the EQUALS() Function.
    Code:
    /*
    Date: Feb. 21, 2015
    To: ALL
    
    
    INTRO:
    This Code is for Fess' Arduino Mega driven, MCP/Auto Pilot panel, (specifically for the MilViz 737-200) utilizing Link2fs_multi v6f.
    It will also mostly work with Stock FSX aircraft. It will NOT work with the PMDG.
    ************************************************************
    **** It is currently incomplete but mostly operational. ****
    ************************************************************
    I have taken Jim's examples and have ran with them.  You may recognise some of the structure and a few variables.
    Most of the variable names I have changed for my own understanding and clarity.
    This code is heavily remarked to help others to learn what I have.
    
    
    FORMATTING:
    I use a double row of asterisks at the beginning and end of all Function Blocks.
    Inside Function Blocks, I use a single row of asterisks to separate unrelated pieces. 
    Most "if" statements are indented for visual understanding to help accommodate those that are learning.
    Some of the "if" "else" statements are in a straight line, this is in the Encoder blocks of the INPUTPINS() Function.
    Some of this code could be refined for efficiency and may well be in the future.
    The primary purpose for the style and formatting is to help others understand. (And myself, least I take sabbatical and forget.)
     
    FINISHING:
    As stated earlier, this is being designed for the MilViz 737-200.  Not all of the Buttons and their light up annunciators work with the MilViz 737.
    I have just discovered how to manipulate LUA Variables, Commands, and Offsets using a custom LUA script and an Arduino outside of Link2FS.
    Of the things that Link2FS can not do, I plan to accomplish with a second Arduino and a LUA script, and then have the 2 Arduinos communicate with each other.
    The whole job could be done outside of Link2FS, with LUA, but I don't feel like re-inventing the wheel, yet.  
    What I have learned from Link2FS has helped me to start learning the LUA scripting process.  
    So in the mean time, I'm content to have Link2FS do what Link2FS does, and I'll work around what it can't.
    Hopefully, stepping up my game in the process.
    
    
    ~Fess
    http://thegeekforge.com
    
    
    
    
    ********* Pin Uses *************
    21      LVL CHG Button
    
    
    22-23     R CRS Encoder
    24-25    V/S Encoder
    26-27    ALT Encoder
    
    
    28    R Flt Director Switch
    29    L Flt Director Switch
    30    CMD B Button
    31    CWS B Button
    32    CMD A Button
    33    CWS A Button
    34    V/S   Button
    35    ALT HLD Button
    36    LNAV Button
    37    VOR LOC Button
    38    APP Button
    39    HDG SEL Button
    40    VNAV Button
    41    ***** NOTE: this pin failed on my Arduino mega so I changed the button to pin 21
    42    SPEED/Mach Button
    43    A/T Arm Switch
    44    SPEED Button
    45    N1 Button
    46    Push Button on HDG Encoder
    47    AP Disengage Switch
    
    
    48-49    HDG Encoder
    50-51    SPD Encoder
    52-53    L CRS Encoder
    
    
    ************ LED Annunciator Pins *************
    2           R Flight Director Light  
    A0    (54)    CWS B Light              
    A1    (55)    CMD B Light              
    A2    (56)    CWS A Light              
    A3    (57)    CMD A Light              
    A4    (58)    V/S Light                
    A5    (59)    ALT HOLD Light           
    A6    (60)    APP Light                
    A7    (61)    VOR LOC Light            
    A8    (62)    LNAV Light               
    A9    (63)    HDG SEL Light            
    A10    (64)    LVL CHG Light            
    A11    (65)    VNAV Light               
    A12    (66)    SPEED Light              
    A13    (67)    N1 Light                 
    A14    (68)    L Flight Director Light  
    A15    (69)    A/T Light                
    *******************************************
    */
    #include "LedControl.h"            // This Library is required to drive the MAX7219 7 segment LED displays.
                                                        //led_Display_1 is the variable name of my set of displays chained
    LedControl led_Display_1 = LedControl(12,10,11,8);    //together running off of pins 10,11,12.  Pin 12 is the DataOut, Pin 11 is
                                                        //Load or CS, and Pin 10 is clock.  The "8" in this statement is for how many displays you have
                                                        //to chain. I have 4 but put 8 in case of expansion. It cost no memory.
    
    
    int CodeIn;                     // Used on all serial reads from Jim's code
    int Count;                      // Used in loops in the EQUALS() function for enumerating Array variables
    int current_pin;                // Used in "for" loops to cycle thru the pins to be processed
    int otherPin;                   // Used in "if" comparisons when checking to see if an Encoder has been turned
    int AP_alt_set[5];              // Makes an Array for the individual digits of the Auto Pilot Altitude Display
    int AP_vs_set[4];               // Makes an Array for the individual digits of the Vertical Speed Display
    int AP_hdg_set[3];              // Array for Heading Display
    int AP_crs_set[3];              // Array for Course Display
    int AP_speed_kt_set[3];         // Array for Speed in Knots Display
    int AP_mach_set[3];             // Array for Mach number Display
    int AP_AutoThrottle_arm;        // State of the Auto Throttle Arm 
    int AP_Flight_Director_Active;    // State of the Flight Director
    
    
    unsigned long time;             // Used in a timer to check how fast the encoder is turning
    unsigned long last_time;        // Also used in the encoder timer as a comparison check
    
    
    char AP_vs_minus;               // Used to designate whether the AutoPilot VS is descending or climbing, "-" or " "
    
    
    String Digit;                   // Used in processing of received data from serial reads
    String Up;                      // For when Rotary Encoder  dial is turned clockwise
    String Down;                    // For when Rotary Encoder  dial is turned counter clockwise
    String current_pin_state;       // The state of an individual pin being processed 
    String current_pin_old_state;    // The previous state of an individual pin being processed for comparison
    String all_pins_state;          // The state of all of the pins that we are using for Encoders, Buttons, and Switches
    String all_pins_old_state;      // The previous state of all of the pins that we are using for Encoders, Buttons, and Switches for comparison
    
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    void setup() 
    {
        last_time = millis();    // Setting up a "previous" time as a starting point for our "Timer" comparison in the Encoder Acceleration section
    
    
        // The MAX72XX is in power-saving mode on start up, we have to do a wakeup call
        delay (500);
        led_Display_1.shutdown(0,false);    // I have 4 displays, these start them up
        delay (500);                        // I put the delay in so they all don't start drawing
        led_Display_1.shutdown(1,false);    // current at the same time.
        delay (500);                        // I had an issue with running on only USB power and getting a display glitch.
        led_Display_1.shutdown(2,false);    // The delay seems to have fixed this issue.
        delay (500);
        led_Display_1.shutdown(3,false);
        // Set the brightness to a lower than medium values 
        led_Display_1.setIntensity(0,8);
        led_Display_1.setIntensity(1,8);
        led_Display_1.setIntensity(2,8);
        led_Display_1.setIntensity(3,8);
        // and clear the display 
        led_Display_1.clearDisplay(0);
        led_Display_1.clearDisplay(1);
        led_Display_1.clearDisplay(2);
        led_Display_1.clearDisplay(3);
    
    
        all_pins_old_state = "111111111111111111111111111111111111111111111111111111111111111111111"; // Setting a starting point for comparison.
        // *** Explanation *** All of the pins previous states are stored as individual characters in the string "all_pins_old_state" as a "0" or a "1".
        // *** Explanation *** We give it a starting point by making it all ones... Further explanation is down in the INPUTPINS() Function.
        
        for (current_pin = 21; current_pin <= 53; current_pin++)    // Get all the pins ready as inputs 
        {
            pinMode(current_pin, INPUT_PULLUP);     // By setting the pins as INPUT_PULLUP it makes them all "HIGH"
                                                    // This lets us use buttons without the need for a "pull up" resistor.
        }
        pinMode(2, OUTPUT);     // All of these Outputs are for LED annunciators
        pinMode(A0, OUTPUT);    // Analog pin A0  is also pin 54
        pinMode(A1, OUTPUT);    // Analog pin A1  is also pin 55
        pinMode(A2, OUTPUT);    // Analog pin A2  is also pin 56
        pinMode(A3, OUTPUT);    // Analog pin A3  is also pin 57
        pinMode(A4, OUTPUT);    // Analog pin A4  is also pin 58
        pinMode(A5, OUTPUT);    // Analog pin A5  is also pin 59
        pinMode(A6, OUTPUT);    // Analog pin A6  is also pin 60
        pinMode(A7, OUTPUT);    // Analog pin A7  is also pin 61
        pinMode(A8, OUTPUT);    // Analog pin A8  is also pin 62
        pinMode(A9, OUTPUT);    // Analog pin A9  is also pin 63
        pinMode(A10, OUTPUT);    // Analog pin A10 is also pin 64
        pinMode(A11, OUTPUT);    // Analog pin A11 is also pin 65
        pinMode(A12, OUTPUT);    // Analog pin A12 is also pin 66
        pinMode(A13, OUTPUT);    // Analog pin A13 is also pin 67
        pinMode(A14, OUTPUT);    // Analog pin A14 is also pin 68
        pinMode(A15, OUTPUT);    // Analog pin A15 is also pin 69
    
    
        Serial.begin(115200);   // Starts up the Serial connection and sets the data rate at 115200
    }    // End of setup
    //**********************************************************************************************************
    //**********************************************************************************************************
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    void loop() 
    { 
        time = millis();    // Used to get the current clock time in milliseconds and is 
    
    
        INPUTPINS();        // Check the Rotary Encoders, Push Buttons and Switches
        
        if (Serial.available()) 
        {
            CodeIn = getChar();
            if (CodeIn == '=') {EQUALS();}      // The first identifier is "="
            // if (CodeIn == '?') {QUESTION();} // The first identifier is "?"
            // if (CodeIn == '/') {SLASH();}    // The first identifier is "/" 
        }
    }    // End of void loop
    //**********************************************************************************************************
    //**********************************************************************************************************
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    char getChar()                      // Get a character from the serial buffer
    {
        while(Serial.available() == 0);    // wait for data
        return((char)Serial.read());      // Thanks Doug
    }                                   // end of getChar
    //**********************************************************************************************************
    //**********************************************************************************************************
    
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    void INPUTPINS() // All of the Encoders, Buttons and Switches are checked for changes
    {
        all_pins_state = ""; // Clear this before the "for" loop because we will recreate it at the bottom one pin at a time
        for (int current_pin = 21; current_pin <=53; current_pin++) // going to cycle thru all input pins 21 - 53      
        {
            current_pin_state = String(digitalRead(current_pin));     // get the state of the current pin and make it a string format
            current_pin_old_state = String(all_pins_old_state.charAt(current_pin - 21));  // acquire the previous state of the current pin
            // *** Explanation *** The previous state of the current pin is acquired by reading a single character in the string "all_pins_old_state" 
            // *** Explanation *** All of the pins, previous states are stored as individual characters in the string "all_pins_old_state" as a "0" or a "1".
            // *** Explanation *** We treat the individual characters as being numbered 0,1,2,3,4,...
            // *** Explanation *** If the current_pin is 25, "all_pins_old_state.charAt(current_pin - 21)" takes (25-21) which = 4. 
            // *** Explanation *** ".charAt" gets the character at position 4 in the string "all_pins_old_state"
            // *** Explanation *** Now we have the current pin's previous state and we can compare it to the current pin's "current" state.        
            if (current_pin_state != current_pin_old_state)            // compare the state of the current pin to its previous state
            {
                // *******************************************************************************************
                // Check the pins of the Left Side COURSE (CRS) Encoder
                if (current_pin == 52) // the 'first' pin of L CRS Encoder
                {
                    otherPin = digitalRead(53);
                    if (current_pin_state == "0")
                    {  
                        if  (otherPin == LOW){ Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                    else
                    {
                        if  (otherPin == HIGH){ Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                }
                if (current_pin == 53) // the 'second' pin L CRS Encoder
                {
                    otherPin = digitalRead(52);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == HIGH){Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                    else
                    {
                        if  (otherPin == LOW){Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                }
                // End of Left Side COURSE (CRS) Encoder Check 
                // *******************************************************************************************
                // Check the pins of the SPEED Encoder
                if (current_pin == 50)
                {
                    otherPin = digitalRead(51);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == LOW){Up = "B15"; ENCODER_UP();}else { Down= "B16"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == HIGH){Up = "B15"; ENCODER_UP();}else { Down= "B16"; ENCODER_DOWN();}
                    }
                }
                if (current_pin == 51)
                {
                    otherPin = digitalRead(50);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == HIGH){Up = "B15"; ENCODER_UP();}else { Down= "B16"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == LOW){Up = "B15"; ENCODER_UP();}else { Down= "B16"; ENCODER_DOWN();}
                    }
                }
                // End of SPEED Encoder Check
                // *******************************************************************************************
                // Check the pins of the HEADING (HDG) Encoder
                if (current_pin == 48)  
                { 
                    otherPin = digitalRead(49);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == LOW){ Up = "A57"; ENCODER_UP();}else { Down= "A58"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == HIGH){ Up = "A57"; ENCODER_UP();}else { Down= "A58"; ENCODER_DOWN();}
                    }
                }
                if (current_pin == 49)
                {
                    otherPin = digitalRead(48);
                    if (current_pin_state == "0")
                    { 
                        if  (otherPin == HIGH){Up = "A57"; ENCODER_UP();}else { Down= "A58"; ENCODER_DOWN();}
                    }
                    else
                    {
                        if  (otherPin == LOW){Up = "A57"; ENCODER_UP();}else { Down= "A58"; ENCODER_DOWN();}
                    }
                }
                // End of HDG Encoder Check
                // *******************************************************************************************
                // Check the pins of the ALTITUDE (ALT) Encoder
                if (current_pin == 26)
                {
                    otherPin = digitalRead(27);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == LOW){ Up = "B11"; ENCODER_UP();}else { Down= "B12"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == HIGH){ Up = "B11"; ENCODER_UP();}else { Down= "B12"; ENCODER_DOWN();}
                    } 
                }    
                if (current_pin == 27)
                {
                    otherPin = digitalRead(26);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == HIGH){ Up = "B11"; ENCODER_UP();}else { Down= "B12"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == LOW){ Up = "B11"; ENCODER_UP();}else { Down= "B12"; ENCODER_DOWN();}
                    }
                }
                // End of ALT Encoder Check
                // *******************************************************************************************
                // Check the pins of the VERTICLE SPEED (V/S) Encoder  
                if (current_pin == 25)
                {
                    otherPin = digitalRead(24);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == LOW){ Up = "B13"; ENCODER_UP();}else { Down= "B14"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == HIGH){ Up = "B13"; ENCODER_UP();}else { Down= "B14"; ENCODER_DOWN();}
                    }
                }
                if (current_pin == 24)
                    {
                    otherPin = digitalRead(25);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == HIGH){Up = "B13"; ENCODER_UP();}else { Down= "B14"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == LOW){Up = "B13"; ENCODER_UP();}else { Down= "B14"; ENCODER_DOWN();}
                    }
                }
                // End of V/S Encoder Check
                // *******************************************************************************************
                // Check the pins of the Right Side COURSE (CRS) Encoder
                if (current_pin == 22)
                {
                    otherPin = digitalRead(23);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == LOW){ Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == HIGH){ Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                }
                if (current_pin == 23)
                {
                    otherPin = digitalRead(22);
                    if (current_pin_state == "0")
                    {
                        if  (otherPin == HIGH){Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                    else
                    { 
                        if  (otherPin == LOW){Up = "A56"; ENCODER_UP();}else { Down= "A55"; ENCODER_DOWN();}
                    }
                }
                // End of Right Side COURSE (CRS) Encoder Check 
                // *******************************************************************************************
                // EPR N1 Button
                if (current_pin == 45)
                {
                    if  (digitalRead(45) == LOW)        // EPR N1 Button is depressed and we need to Send a command
                    { 
                        Serial.println ("ZZ778560");    // Send the Toggle command
                    }
                }
                // *******************************************************************************************
                // SPEED Button
                if (current_pin == 44)
                {
                    if  (digitalRead(44) == LOW) // SPEED Button is depressed and we need to Send a command
                    { 
                        Serial.println ("ZZ778280");
                    }
                }
                // *******************************************************************************************
                //Auto Throttle Arm Switch
                if (current_pin == 43)
                {
                    if  (digitalRead(43) == HIGH and AP_AutoThrottle_arm == 1 )    //Auto Throttle arm ON
                    { 
                        Serial.println ("B34");
                    }
                    if  (digitalRead(43) == LOW and AP_AutoThrottle_arm ==0 )    //Auto Throttle arm OFF
                    { 
                        Serial.println ("B34");
                    }
                }
                // *******************************************************************************************
                // SPD/MACH Button
                if (current_pin == 42)
                {
                    if  (digitalRead(42) == LOW)
                    { 
                        Serial.println ("ZZ778270"); 
                    }
                }
                // *******************************************************************************************    
                // LVL CHG Button
                if (current_pin == 21)
                {
                    if  (digitalRead(21) == LOW)  
                    { 
                        Serial.println ("ZZ778550"); 
                    }
                } 
                // *******************************************************************************************
                // VNAV  Button(FMS/NAV1 on MILVIZ 737-200)
                if (current_pin == 40)
                {
                    if  (digitalRead(40) == LOW)  
                    { 
                        Serial.println (""); 
                    }
                }    
                // *******************************************************************************************
                // HDG Button
                if (current_pin == 39)
                {
                    if  (digitalRead(39) == LOW)  
                    { 
                        Serial.println ("B04"); 
                    }
                }
                // *******************************************************************************************
                // APP Button
                if (current_pin == 38)
                {
                    if  (digitalRead(38) == LOW) 
                    { 
                        Serial.println ("B08");
                    }
                }
                // *******************************************************************************************
                // VOR LOC Button
                if (current_pin == 37)
                {
                    if  (digitalRead(37) == LOW) 
                    { 
                        Serial.println ("B07");
                    }
                }
                // *******************************************************************************************
                // LNAV Button
                if (current_pin == 36)
                {
                    if  (digitalRead(36) == LOW) 
                    { 
                        Serial.println ("B10");
                    }
                }
                // *******************************************************************************************
                // ALT HOLD Button
                if (current_pin == 35)
                {
                    if  (digitalRead(35) == LOW) 
                    { 
                        Serial.println ("B05");
                    }
                }
                // *******************************************************************************************
            }   // End of IF Current Pin State Check
            all_pins_state += current_pin_state; // Constructs what will become the all_pins_old_state after the "for" loop is done
        }   // End of 'for' loop
        all_pins_old_state = all_pins_state;    // all_pins_old_state is updated for the next trip thru the "for" loop
    }    // End of INPUTPINS() Function
    //**********************************************************************************************************
    //**********************************************************************************************************
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    void ENCODER_UP()
    {
        if (time - last_time < 100)     //  ************ Fess' Acceleration Code ***********************
                                        //  This is what I added to make the encoder "accelerate". You
        {                               //  kind of need to think of it from bottom to top.
            Serial.println (Up);        //  Basically if you turn the knob slower than 250ms you get one tick.
            Serial.println (Up);        //  If you turn the knob faster than 250ms you get an extra tick.
        }                               //  If you turn the knob faster than 175ms you get 2 extra ticks.
        if (time - last_time < 175)     //  If you turn the knob faster than 100ms you get 4 extra ticks.
        {                               //  On my Elma E37 dual concentric encoder 1 fast turn gets you
            Serial.println (Up);        //  about 45 degrees or more on the Heading Bug or OBS.
        }                               //
        if (time - last_time < 250)     //  *****
        {                               //  
            Serial.println (Up);        //  *****
        }                               //
        Serial.println(Up); 
        last_time = time;
    }    // End of ENCODER_UP() Function
    //**********************************************************************************************************
    //**********************************************************************************************************
    
    
    //**********************************************************************************************************
    //**********************************************************************************************************
    void ENCODER_DOWN()
    {
        if (time - last_time < 100)  //******** More Acceleration Code, same as above ******************
        {
            Serial.println (Down);
            Serial.println (Down);
        }
        if (time - last_time < 175)
        {
            Serial.println (Down);
        }
        if (time - last_time < 250)
        {
            Serial.println (Down);
        }
        Serial.println(Down);  
        last_time = time;
    }    // End of ENCODER_DOWN() Function
    //**********************************************************************************************************
    //**********************************************************************************************************
    20150221_021547.jpg20150221_022204.jpg
    I have more pictures of various stages of construction that I intend to publish later.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  2. #12
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    236
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    UPDATE PART II:


    Here is the second half of the code that contains the EQUALS() Function.
    Edit: I added some remarks that I had previously omitted in this section.

    Code:
    /*
                  *****************************************
                  ***** Info on how the Displays work *****
                  *****   This is an excerpt from my  *****
                  *****        Radio Box Code         *****
                  *****************************************
          led_Display_1.setDigit(0,7,Com1Active[0],false);    // setDigit(0,7,Com1Active[0],false) The 0 is the first display, 7 is the first character in the 
          led_Display_1.setDigit(0,6,Com1Active[1],false);    // display, Com1Active[0] is the stored Integer to be displayed, false is no decimal point.
          led_Display_1.setDigit(0,5,Com1Active[2],true);     // "true" puts in the decimal point
          led_Display_1.setDigit(0,4,Com1Active[3],false);    // setDigit is for putting in numbers
          led_Display_1.setDigit(0,3,Com1Active[4],false);    // You can also use setChar for putting in some letters
                                                              // character, symbols, and ' ' space.
                                                              // NOTE: setChar has to use single quote 'A'
                                                              // Double quote "A", is for Strings and wont work.
              
          ****************** The 300 Level Remarks ****************************************
           In the "300 Level Class", you can use setRow to light one of the 7 segment
           displays using binary or hex equivalent. It would look like this:
           led_Display_1.setRow(1,4,B00110000,false) that would display the number 1.
          
                    __A_      The segments on my displays are lettered A thru H
                  F|    |B    However, using the setRow with Binary the H (decimal point) comes first.
                   |__G_|             If you want an 8 with no decimal...
                  E|    |C             H A B C D E F G
                   |__D_|.H          B 0 1 1 1 1 1 1 1   = 8
                                     B 0 1 1 1 0 0 0 0   = 7
                                     
          *********************************************************************************
    */
    //**********************************************************************************************************
    //**********************************************************************************************************
    void EQUALS()  
    {    // The first identifier was "="
        CodeIn = getChar();     // Get another character
        switch(CodeIn) 
        {                       // Now lets find what to do with it
        // *******************************************************************************************  
        case 'b':    //  AP altitude set
            Count = 0;                  // clear the Count
            while (Count < 5)           // we will count to 5 from 0 to 4
            {
                Digit = "";              // clears the string variable Digit
                Digit += getChar();      // Makes the string Digit what ever getChar() is holding 
                AP_alt_set[Count] = Digit.toInt();       // Turns the string Digit into an Integer and
                Count++;                                 // then stores it in the Array AP_alt_set[] 0,1,2,3,4
            }
            led_Display_1.setDigit(1,3,AP_alt_set[0],false);    // First digit of Alt Set is displayed  
            led_Display_1.setDigit(1,2,AP_alt_set[1],false);    // Second digit of Alt Set is displayed 
            led_Display_1.setDigit(1,1,AP_alt_set[2],false);    // Third digit of Alt Set is displayed 
            led_Display_1.setDigit(1,0,AP_alt_set[3],false);    // Fourth digit of Alt Set is displayed 
            led_Display_1.setDigit(2,7,AP_alt_set[4],false);    // Fifth digit of Alt Set is displayed 
        break;                                                  // false denotes NO decimal point
        case 'c':    //  AP vertical speed set
            Count = 0;
            while (Count < 4)
            {
                Digit = "";
                Digit += getChar(); 
                if (Count == 0)
                {
                    if (Digit == "-")
                    {
                        AP_vs_minus = '-';
                    }
                    else 
                    {
                        AP_vs_minus = ' ';
                    }
                    Digit = "";
                    Digit += getChar();
                }
                AP_vs_set[Count] = Digit.toInt();
                Count++;
            }
            led_Display_1.setChar(2,4,AP_vs_minus,false);
            led_Display_1.setDigit(2,3,AP_vs_set[0],false);
            led_Display_1.setDigit(2,2,AP_vs_set[1],false);
            led_Display_1.setDigit(2,1,AP_vs_set[2],false);
            led_Display_1.setDigit(2,0,AP_vs_set[3],false); 
        break;
        case 'd':    //  AP heading set
            Count = 0;
            while (Count < 3)
            {
                Digit = "";
                Digit += getChar();         
                AP_hdg_set[Count] = Digit.toInt();
                Count++;
            }
            if (AP_hdg_set[0]==0 and AP_hdg_set[1]==0 and AP_hdg_set[2]==0)
                {
                    AP_hdg_set[0]=3; AP_hdg_set[1]=6;
                }
            led_Display_1.setDigit(1,6,AP_hdg_set[0],false);
            led_Display_1.setDigit(1,5,AP_hdg_set[1],false);
            led_Display_1.setDigit(1,4,AP_hdg_set[2],false);     
        break;   
        case 'e':    //  AP course set
            Count = 0;
            while (Count < 3)
            {
                Digit = "";
                Digit += getChar();
                AP_crs_set[Count] = Digit.toInt();
                Count++;
            }
            if (AP_crs_set[0]==0 and AP_crs_set[1]==0 and AP_crs_set[2]==0)
            {
                AP_crs_set[0]=3; AP_crs_set[1]=6;
            }
            led_Display_1.setDigit(0,7,AP_crs_set[0],false);
            led_Display_1.setDigit(0,6,AP_crs_set[1],false);
            led_Display_1.setDigit(0,5,AP_crs_set[2],false);
            led_Display_1.setDigit(3,2,AP_crs_set[0],false);
            led_Display_1.setDigit(3,1,AP_crs_set[1],false);
            led_Display_1.setDigit(3,0,AP_crs_set[2],false);  
        break;
        case 'f':    //  AP speed knots set kts
            Count = 0;
            while (Count < 3)
            {
                Digit = "";
                Digit += getChar();
                AP_speed_kt_set[Count] = Digit.toInt();
                Count++;
            }
            led_Display_1.setDigit(0,2,AP_speed_kt_set[0],false);
            led_Display_1.setDigit(0,1,AP_speed_kt_set[1],false);
            led_Display_1.setDigit(0,0,AP_speed_kt_set[2],false);
        break;
        case 'g':    //  AP mach set 
            Count = 0;
            while (Count < 3)
            {
                Digit = "";
                Digit += getChar();
                if (Digit ==".")
                {
                    Digit = "";
                    Digit += getChar();
                }
                AP_mach_set[Count] = Digit.toInt();
                Count++;
            }  
            led_Display_1.setChar(3,7,' ',false);
            led_Display_1.setDigit(3,6,AP_mach_set[0],true);
            led_Display_1.setDigit(3,5,AP_mach_set[1],false);
            led_Display_1.setDigit(3,4,AP_mach_set[2],false);      
        break;
        // *******************************************************************************************
        case 'a':    //  AP active
            Digit = "";
            Digit += getChar(); 
            if (Digit == "1")
            {
                digitalWrite(57, HIGH);
            }
            else
            {
                digitalWrite(57, LOW);
            }
        break;
        case 't':    //  AP AutoThrottle armed on/off  
            Digit = "";
            Digit += getChar();
            AP_AutoThrottle_arm = Digit.toInt();
            if (AP_AutoThrottle_arm == 1 )
            {
                digitalWrite(69, HIGH);
            }
            else
            {
                digitalWrite(69, LOW);
            }
        break;
        case 'q':    //  Flight Director Active 
            Digit = "";
            Digit += getChar();
            AP_Flight_Director_Active = Digit.toInt();
            if (AP_Flight_Director_Active == 1 )
            {
                digitalWrite(A1, HIGH);
            }
            else
            {
                digitalWrite(A1, LOW);
            }
        break;
        case 'k':    //  Altitude lock active
            Digit = "";
            Digit += getChar();
            if (Digit == "1")
            {
                digitalWrite(59, HIGH);
            }
            else
            {
                digitalWrite(59, LOW);
            }
        break;
        case 'm':    //  APP 
            Digit = "";
            Digit += getChar();          
            if (Digit == "1")
            {
                digitalWrite(60, HIGH);
            }
            else
            {
                digitalWrite(60, LOW);
            }
        break;
        case 'j':    //  Heading lock Active
            Digit = "";
            Digit += getChar();         
            if (Digit == "1")
            {
                digitalWrite(63, HIGH);
            }
            else
            {
                digitalWrite(63, LOW);
            }
        break;
        case 'p':    //  VLOC
            Digit = "";
            Digit += getChar();         
            if (Digit == "1")
            {
                digitalWrite(61, HIGH);
            }
            else
            {
                digitalWrite(61, LOW);
            }
        break;
        case 'v':    //  v/s
            Digit = "";
            Digit += getChar();         
            if (Digit == "1")
            {
                digitalWrite(58, HIGH);
            }
            else
            {
                digitalWrite(58, LOW);
            }
        break;
        case 'o':    //  LNAV
            Digit = "";
            Digit += getChar();         
            if (Digit == "1")
            {
                digitalWrite(62, HIGH);
            }
            else
            {
                digitalWrite(62, LOW);
            }
        break;
                // etc etc etc
                // You only need the "Case" testing for the identifiers you expect to use.
        }    // End of Switch case
    }    // End of EQUALS() Function
    //**********************************************************************************************************
    //**********************************************************************************************************

    UPDATE 2016-3-19:
    Attached is the whole code package.
    Contains Code for both Arduinos and the LUA script.


    ~Fess
    Attached Files Attached Files
    Last edited by Fess_ter; 02-21-2015 at 11:57 AM. Reason: Forgot to add some stuff
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  3. #13
    25+ Posting Member
    Join Date
    Jan 2015
    Location
    Manchester UK
    Posts
    38
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Hi Fess, I've used a couple of your max7219 ideas, thanks. Have you considered using shift registers for the inputs/outputs ? I've just about got my code finished using around twenty pins in total. 12 of those are for the rotarys. It certainly frees up a lot of pins, just means a small sub-board to mount the ic's. You mentioned the vertical speed switch. Is it not possible to mount a rotary encoder mounted sideways on a bracket with a largeish wheel poking through the slot. Just about to start my construction so will see how it turns out.
    regards

  4. #14
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    236
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    heywoodp,

    I have come a long way from when this post was started. (11 months ago )

    If you notice in my later pictures, I do have an encoder mounted sideways for the Vert Speed wheel.
    For the Wheel I used a rubber chair foot from an Ace Hardware Store. It has a metal washer inside of it. I took one of my rotary knobs and cut the plastic off so it was just the brass collet. The washer in the rubber foot needed just a little filing to let the collet nut/screw pass thru. Put the screw in and tighten it down.
    For mounting I cut and constructed a perpendicular bracket out of wood, (yes metal would be better) its what I had at the time and it is mounted halfway thru the base board of the build.

    20140409_171014.jpg20140413_234429.jpg20140413_230453.jpg

    I have 6 encoders for 12 pins, 17 LEDs (3 stand alone the 14 on push buttons). Those, I prob could have used a shift reg for, but I have not tried that yet.
    My displays only use 3 pins, DATA, CLOCK and LOAD/CS. All buttons and switches use 19 pins. So all in thats 51 pins, with some left over on the Mega.
    I also use 2 pins to communicate with a second Arduino using the "WIRE" protocol/library. The second arduino communicates with a LUA script to do the things Link2FS can't.

    I am 90% finished to fully operational with my code. Once I complete it, clean it, and remark it, I will post the whole project with photos, code, pitfalls and all.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  5. #15
    25+ Posting Member
    Join Date
    Jan 2015
    Location
    Manchester UK
    Posts
    38
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Woops. I should've looked closer at the picture. I'm some months behind you in building. Did you use some fine plywood in front of the main piece ? I tried Jim's radio panel as a test using plexiglass but wasn't overjoyed at the results.

    paul h

  6. Likes Dejavu liked this post
  7. #16
    New Member
    Join Date
    Apr 2015
    Location
    United States
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    can someone tell me ,how to load the code to arduino

  8. #17
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Mar 2014
    Location
    TURKEY
    Posts
    6
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Silvano

    Download the Arduino software
    Connect the usb cable to Arduino Board
    upload code


  9. #18
    New Member
    Join Date
    Apr 2015
    Location
    United States
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Quote Originally Posted by Dejavu View Post
    Silvano

    Download the Arduino software
    Connect the usb cable to Arduino Board
    upload code

    i did , but , the black space on the bottom with the red letter is not leting compeling ,and say that is a problem
    uploading to bord.

  10. #19
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    236
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Silvano,

    If you are trying to load the code that I posted in this thread... It was written for an Arduino MEGA and will not work on another board like the UNO.

    A google search with the error / problem will likely give you the correct answer.

    If you have never loaded code on an Arduino then you need to do some basic research.

    Hint: Arduino IDE, Tools, Board, Port. (google)

    This is not the thread for basic troubleshooting.
    If you still can't find your way... Then start a new Post requesting help.



    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  11. #20
    New Member
    Join Date
    Jan 2010
    Location
    Brazil
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Boeing Style MCP/Autopilot panel

    Hello Fess


    I am eagerly awaiting the completion of code to ride my MCP, already I tested your entire code and thank you for your work !!!


    Leandro

Page 2 of 11 FirstFirst 123456 ... LastLast