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

    Radio panel code help

    Good Morning Everyone,

    First of all I would like to thank Jim for all his great work with Link2FS! I am continually impressed by the scope and flexibility of this amazing program. Jim - sorry I was unavailable to assist with beta testing 6 - my family and work commitments sometimes overtake my hobby! I am now using 6 and will provide input wherever I can.

    I am not a total newbie to arduino, so far I have built an annunciator panel, a custom throttle quadrant from scratch, revived an elite yoke by converting it from game port to USB and built a main panel for a king air 350.

    I am attempting to make my radio panel with rotary encoders, and what I want to happen is when I rotate the encoder normally it will increment MHz, but when depressed and rotated it will increment KHz. I have the MHz side working but I can't work out how to make the KHz cycle when depressed. If anyone can assist with a code snippet I would be grateful.

    I believe in giving back what I can, I am happy to share all my sketches with anyone who would like them, I am also an aviation instructor so I can assist with any aviation type questions.

    Thank you in advance for your help.

    Regards,

    Michael

  2. #2
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    232
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Radio panel code help

    Hello, Michael.
    You appear to be well versed with the arduino and L2FS and simply need a second pair of eyes; therefore, to keep troubleshooting simplistic (especially without seeing your code), I recommend creating separate methods:

    Code:
    void loop(){
    readEncoder();
    buttonpress = digitalRead(pinX);
    
    if (buttonpress == LOW){doThis();}else{doThat();}
    }
    
    void readEncoder(){
    // read encoder pins
    }
    
    
    void doThis(){
    // MHZ stuff
    }
    
    void doThat(){
    //KHZ stuff
    }
    Personally, I have found the creation of separate methods is easier on the eyes... especially when troubleshooting.

    I doubt this helps, but I wanted to present an alternative way of processing the logic.

  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: Radio panel code help

    Hello KA-B350,

    I'm glad you brought this up as I was thinking of building a different version of my radio stack, because Dual Concentric Encoders are darned expensive.

    If you are using Jim's example code and or modified it...
    The push button condition must be outside of the normal INPUTPINS() function.
    You will likely need either, 2 INPUTPINS() functions, or 2 different "for" loops inside the INPUTPINS() function.

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

  4. #4
    75+ Posting Member
    Join Date
    Apr 2014
    Location
    Tampa, FL, USA, Earth..umm
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Radio panel code help

    Quote Originally Posted by Fess_ter View Post
    Hello KA-B350,

    If you are using Jim's example code and or modified it...
    The push button condition must be outside of the normal INPUTPINS() function.
    You will likely need either, 2 INPUTPINS() functions, or 2 different "for" loops inside the INPUTPINS() function.
    Fess, what does this mean? I'm not sure I followed that or followed that with my code.

    This is part of my COMs code. If the button is pressed, adjust the KHz up or down. Otherwise, adjust the MHz. Is this not correct? Other than it works, is there a better or easier way? Thanks!

    Code:
    void INPUTS() {
    char buffer [33];  
    
    // rotary 1 = COM 1
    
    qe1Move=qe1.tick();
    buttonState == "";
    buttonState = String(digitalRead(52));
    //if (buttonState != "1") { Serial.println("Pressed..."); }
    if (qe1Move=='<') { if (buttonState == "1") { Serial.println("A02");} else { Serial.println("A04");  } }
    if (qe1Move=='>') { if (buttonState == "1") { Serial.println("A01");} else { Serial.println("A03"); } }
    
    // rotary 2 = NAV 1
    
    qe2Move=qe2.tick();
    buttonState == "";
    buttonState = String(digitalRead(46));
    //if (buttonState != "1") { Serial.println("Pressed..."); }
    if (qe2Move=='<') { if (buttonState == "1") { Serial.println("A14");} else { Serial.println("A16");  } }
    if (qe2Move=='>') { if (buttonState == "1") { Serial.println("A13");} else { Serial.println("A15"); } }
    
    ...

  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: Radio panel code help

    I'm jazzed!
    I just tested what I said above and it worked!
    I don't know why I didn't think of trying this sooner.
    Thanks for the inspiration.

    MikeB1028,
    It looks like you using a quadrature library?
    I am not using a quadrature library.
    There is always more than one way to skin a cat.
    Your code looks efficient.
    Mine is not so efficient, yet.... But, as proof of concept, it works.

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

  6. #6
    75+ Posting Member
    Join Date
    Apr 2014
    Location
    Tampa, FL, USA, Earth..umm
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Radio panel code help

    Great news Fess! Isn't it cool when things work like that. There is so much that can be done.

    Thanks for the info. Yes I'm using a library. I wasn't sure if I was coding in a good way or bad way and it was just working because it worked. I'm still working on coding and wiring.

    I don't want to hijack this thread away from the OP. But hopefully some of this is helping him (Michael).

    Mike

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

    Re: Radio panel code help

    Gents,

    Thank you so much for your kind and generous assistance. All of you have helped shape my thinking, JMeller, Fess_ter and Mike B I cannot thank you enough. Yes, the primary motivation for attempting this is the cost of double spin encoders! I am building a King Air 350 sim and having a lot of fun in the process! I am working through now sorting out the comms panel code, I will post my finished product soon!

    Thank you again, if there is anything I can help anyone with please ask!

    Cheers,
    Michael

  8. Thanks alechindle thanked for this post

Tags for this Thread