Results 1 to 9 of 9
  1. #1
    10+ Posting Member
    Join Date
    Jul 2016
    Location
    Stockholm
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Code Support 101

    Im struggling to get this LED to show my Com from FSX via Link2fs, i found this code online but u cant get it to verify..
    Can some skilled helping person help me in the right direction =)

    Code:
    #include 
     LedControl lc=LedControl(10,12,11,8);
    
    
    int ExtFlg; // Serial Character Read
    int SegDig;
    
    
    
     void setup()
     {
      
     lc.shutdown(0,false);
     lc.shutdown(1,false);
     lc.setIntensity(0,7);
     lc.setIntensity(1,7);
     lc.clearDisplay(0);
     lc.clearDisplay(1);
    
    
     Serial.begin(115200);
    
    
     // This does a quick test of all the segments
    
    
     for(int i=0;i<8;i++)
     {
     lc.setDigit(0,i,8,false);
     lc.setDigit(1,i,8,false);
     delay(250);
     }
    
    
     for(int i=8;i>0;i--)
     {
     lc.setChar(0,i,' ',false);
     lc.setChar(1,i,' ',false);
     delay(250);
     }
    
    
     {lc.clearDisplay(0);
     lc.clearDisplay(1);}
     delay(250);
    
    
     }
    
    
     void loop()
     {
     ExtFlg = getChar();
    
    
     if (ExtFlg == 'd'){ // Comm 1 Radio Freq
    
    
     SegDig = getChar(); //Read the 1st character sent but don't send it to the display
    
    
     SegDig = getChar(); //Read the 2nd digit sent and display it
     lc.setChar(0,7,SegDig,false);
    
    
     SegDig = getChar(); //Read the 3d digit sent and display it
     lc.setChar(0,6,SegDig,true);
    
    
     SegDig = getChar(); //DONT READ THE DOT
    
    
     SegDig = getChar(); //Read the 4th digit sent and display it
     lc.setChar(0,5,SegDig,false);
    
    
     SegDig = getChar(); //Read the 5th digit sent and display it
     lc.setChar(0,4,SegDig,false);
    
    
     SegDig = getChar(); //read last digit but dont display it
    
    
     /*
     lc.setChar(a,b,c,d);
     a = select board 0 -7 [You can drive up to 8 of these board on three arudino pins]
     b = select segment display position 0 - 7 [there are 8 7segment display per board]
     c = data to display [0-9]
     d = true = display "." false = no decimal point
     */
    
    
     } // END Comm 1 Radio Freq
    
    
     } End program loop
    
    
     // Serial Read Function
     char getChar()
     {
     while(Serial.available() == 0);
     return((char)Serial.read());
     }
     

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

    Re: Code Support 101

    Here is my stuff. Double check the connections on Max7219 and Arduino pins, I had some remarks on my old radio code labeled incorrectly. These are correct here.
    Someof my variables you may not need.
    Code:
    #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 12,10,11.  Pin 12 is the DataOut, Pin 11 is
                                                        //Load or CS, and Pin 10 is clock.  The 8 is for how many displays you have
                                                        //to chain. I have 4 but put 8 incase of expansion. It cost no memory.
    int CodeIn;      // used on all serial reads from Jim's code
    
    
    String Digit;      // 
    String OuterUp;    // For when Rotary Encoder Outer dial (the fat one) is turned clockwise
    String OuterDown;  // For when Rotary Encoder Outer dial is turned counterclockwise
    String InnerUp;    // For when Rotary Encoder Inner dial (the skinny one)is turned clockwise
    String InnerDown;  // For when Rotary Encoder Inner dial is turned counterclockwise
    
    
    int Rotary;        // This variable is for the state of the Rotary Selector Function switch. (NOTE: Not to be confused with the Rotary Encoder.)
                       // 
    
    
    int Selector;      // Used as a counter from the state of the Encoder Push Button (press once its 1, twice its 2 etc as needed
                       // If I have 4 things to select and the press gets to 5 we code it back to 1
    int LastSelector;  // Used to remember last count of "Selector" from the Encoder Push Button
    
    
    int Count;           // This variable used in loops in the EQUALS() function
    
    int Com1Active[5];   // Hopefully all of these variable names are mostly obvious.
    int Com1StdBy[5];    // They will be used to store the extractions in array format.
    int Nav1Active[5];   // The [n] with a number in it tells the arduino to make an array of the size n
    int Nav1StdBy[5];    // The reason I store the information in arrays is to be able to display it without
    int Com2Active[5];   // delay when the function selector dial gets switched.   
    int Com2StdBy[5];    //  
    int Nav2Active[5];   // 
    int Nav2StdBy[5];    //
    Down in the Equals section...

    Code:
    void EQUALS(){      // The first identifier was "="
           CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'A':    //COMM1 Active
            Count = 0;
            while (Count < 5 )           // Counting from 0 to 4. Five digits to store in the Com1Active Freq
            {                            //
                Digit = "";                // Clear Digit 
                Digit += getChar();        // Get a character put it in the String "Digit"    
                if (Digit ==".")          // ******   This looks for the "." *************
                {
                    Digit = "";           // If we find the "." we clear it and get the next digit
                    Digit += getChar();  //  Because we know where the "." always goes. 
                } 
                Com1Active[Count] = Digit.toInt();  // Turn String Digit into an Integer and store it in the Array for later
                Count++;                            // add one to the count
            }
            if (Rotary ==2)                  // Because our display is used for multiple radios we only want it updating the display for the selected
            {                                // radio(s)
                led_Display_1.setDigit(0,7,Com1Active[0],false);
                led_Display_1.setDigit(0,6,Com1Active[1],false);
                led_Display_1.setDigit(0,5,Com1Active[2],true);
                led_Display_1.setDigit(0,4,Com1Active[3],false);
                led_Display_1.setDigit(0,3,Com1Active[4],false);
            }
            
        break;
        case 'B':       //COMM1 Standby
            Count = 0;
            while (Count <5 )
            {
                Digit = "";
                Digit += getChar();
                if (Digit ==".")
                {
                    Digit = "";
                    Digit += getChar();
                }
                Com1StdBy[Count] = Digit.toInt();
                Count++;
            }
            if (Rotary ==2)
            {
                led_Display_1.setDigit(0,0,Com1StdBy[0],false);
                led_Display_1.setDigit(1,7,Com1StdBy[1],false);
                led_Display_1.setDigit(1,6,Com1StdBy[2],true);
                led_Display_1.setDigit(1,5,Com1StdBy[3],false);
                led_Display_1.setDigit(1,4,Com1StdBy[4],false);
            }
            
        break;
       //etc
        }
    }
    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

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

    Re: Code Support 101

    This code is based on Jim's examples and expanded....

    In the above you need a Void Loop similar to this...

    Code:
    void loop() 
    { 
        time = millis();                // This is used to get the current clock time in milliseconds and is 
                                      // used in the INPUTPINS() section for "acceleration" on the encoder, and debounce.
        
        INPUTPINS();                    //Check the Simconnect and "keys" section
        if (Serial.available()) 
        {
            CodeIn = getChar();
            if (CodeIn == '=') 
            {
                EQUALS();              // The first identifier is "="
            } 
            // if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
            // if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
            // if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
        }
      
    }                             //end of void loop
    You will also need this...

    Code:
    //*********************************************************
    //*********************************************************
    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
    //*****************************************************************
    //*****************************************************************
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  4. #4
    10+ Posting Member
    Join Date
    Jul 2016
    Location
    Stockholm
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Code Support 101

    Just woke up here, so excuse if im getting this a little wrong.
    But that code can be used with leobodnars dual encoder and some 7219s correct?
    Im trying to find how you swap between the coms, and whats pins the encoders are connected. See that its not a normal quad aprroach

    My rig was intended to use a rotary switch with 7 positions, just like Saitek (i have actually borrowd the rotary switches and i wanted to try to implement them) but maybe this solution is smoother.

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

    Re: Code Support 101

    On my Radio I use a single Elma E37 Dual Concentric rotary encoder with push button Switch on the shaft. I bought it from Leo.
    My Displays are Max7219 Tube Display Modules.

    I use a Rotary Switch to select the radio functions.
    Code:
                                    // These are the pins attached to the rotary switch to select function
    	pinMode(A1, INPUT_PULLUP);      // xponder
    	pinMode(A2, INPUT_PULLUP);      // com1 nav1
    	pinMode(A3, INPUT_PULLUP);      // MCP
    	pinMode(A4, INPUT_PULLUP);      // com2 nav2
    	pinMode(A5, INPUT_PULLUP);      // ADF
    When A2 is active, the radio displays COM1 (Active and Standby) on the left side displays and NAV1 (Active and Standby) on the right side displays.
    To choose which one to "change" you press the button on the Encoder shaft and it toggles between COM and NAV. Then you dial the desired Standby Freq.
    Attached Files Attached Files
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

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

    Re: Code Support 101

    Japmaco,

    Here is a Video of my radio function.
    https://youtu.be/kNmnKR1woW8

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

  7. #7
    10+ Posting Member
    Join Date
    Jul 2016
    Location
    Stockholm
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Code Support 101

    Quote Originally Posted by Fess_ter View Post
    Japmaco,

    Here is a Video of my radio function.
    https://youtu.be/kNmnKR1woW8

    ~Fess
    Thx! I only have the 8 digits modules so. I have to split it up more. Use 5 of 8 digits for each act/stby

  8. #8
    New Member
    Join Date
    Jun 2016
    Location
    canada
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Code Support 101

    Hi Japmaco.

    I am relatively new here and have been looking for same coding that you are. I couldn't find anything simple so I started hunting around the net to see what I could come up with. Here is what I have pieced together from several sites. This code works with nothing else connected to your Arduino. If you change COM1 in FS, it will change the display.

    Code:
    #include "LedControl.h"              
    
    
    LedControl COM1_LED = LedControl(12,10,11,1);  // Pin 12=DIN,PIN11=CS,PIN10=CLK.  
                                        
                                                      
    int CodeIn;      
    String Digit;    
    int Count;       
    int COM1_Set[5];   // 5 Digit array for displaying COM1 numbers
     
     
     
    
    
    //***( Void SEtup() )***
     
    void setup() 
    {
      //wakeup display
        COM1_LED.shutdown(0,false);      
    
    
        //clear display 
        COM1_LED.clearDisplay(0);
        
        //set brightness 
        COM1_LED.setIntensity(0,9);
    
    
       Serial.begin(115200);   
    }
    //***( void setup END() )***
    
    
    
    
    //*****( start  void loop() )*****
     
    void loop() 
    { 
        if (Serial.available()) 
        {
            CodeIn = getChar();
            if (CodeIn == '=') 
          {
                EQUALS();          // first identifier is "="
          } 
    
    
      }
    }                            
    //****(end void loop )****
    The only problem I have with this code now is the second digit in my display is ALWAYS 0 (zero). Can anyone shed light on this? EDIT: I think it has to do with the 'decimal' from FS... now how to ignore the decimal/solve the issue.


    Attached Images Attached Images

  9. #9
    New Member
    Join Date
    Jun 2016
    Location
    canada
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Code Support 101

    ...the power of perseverance! I realized that I had to ignore the 4th character in the string. So if you compare this code to the above code, you can see how I did it. My array now has 6 places and I ignore the 4th location (COM1_Set[3]). Now, I'm not a programmer so there may be a smarter, more efficient way of doing this (and I'm very open to suggestions), but this is the way I succeeded.

    To your original request Japmaco, if you paste this code in a new arduino sketch and upload it to your board, and in Link2FS selecting SimConnect Extractions1 and checking the =A Com1 frequency, your 8 digit display will show whatever is the active com in FS

    (woo hoo!)

    Code:
    #include "LedControl.h"              
    
    
    LedControl COM1_LED = LedControl(12,10,11,1);  // Pin 12=DIN,PIN11=CS,PIN10=CLK.  
                                        
                                                      
    int CodeIn;      
    String Digit;    
    int Count;       
    int COM1_Set[6];   // 5 Digit array for displaying COM1 numbers
     
     
     
    
    
    //***( Void SEtup() )***
     
    void setup() 
    {
      //wakeup display
        COM1_LED.shutdown(0,false);      
    
    
        //clear display 
        COM1_LED.clearDisplay(0);
        
        //set brightness 
        COM1_LED.setIntensity(0,9);
    
    
       Serial.begin(115200);   
    }
    //***( void setup END() )***
    
    
    
    
    //*****( start  void loop() )*****
     
    void loop() 
    { 
        if (Serial.available()) 
        {
            CodeIn = getChar();
            if (CodeIn == '=') 
          {
                EQUALS();          // first identifier is "="
          } 
    
    
      }
    }                            
    //****(end void loop )****
    
    
    
    
    //****( Start  getChar() Function )****
     
    char getChar()  // Get a character from serial buffer
    {
      while(Serial.available() == 0);   // wait for data
      return((char)Serial.read());      // Thanks Doug
    }                                  
    //****( end getChar Function )*****
    
    
    
    
    //******( start  EQUALS() Function )*****
     
    void EQUALS()     // te first identifier is "="
    {  
       CodeIn = getChar();   // Get next character
       switch(CodeIn)        // Case tests
        {
            case 'A':               //  Com1 Set
                Count = 0;          // clear the Count
                while (Count < 6)   // count 0 to 5
                {
                    Digit = "";          // clear string variable Digit
                    Digit += getChar();  // string Digit what ever getChar() is holding
                     
                     
                    COM1_Set[Count] = Digit.toInt(); // turn string Digit into Integer stores
                                                       // it in the Com1_Set[] 0,1,2,3,4,5
                    Count++;
                }
                
                COM1_LED.setDigit(0,4,COM1_Set[0],false);   // first digit of COM1
                COM1_LED.setDigit(0,3,COM1_Set[1],false);   // second digit of COM1
                COM1_LED.setDigit(0,2,COM1_Set[2],true);    // third digit of COM1
                COM1_LED.setDigit(0,1,COM1_Set[4],false);   // fourth digit of COM1
                COM1_LED.setDigit(0,0,COM1_Set[5],false);   // fifth digit of COM1 
                                                                  
            break;
    
    
        } //   end Switch Case 
    }
    //** end  EQUALS() Function **