Results 1 to 6 of 6
  1. #1
    New Member
    Join Date
    Dec 2017
    Location
    USA
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    link2fs throttle

    Hey guys, I'm pretty new to this D.I.Y cockpit's , so I started messing around with link2fs, it work nicely, until i decided to manage throttle with a potentiometer.
    I got jim's example code, Which is this:



    /*

    This code is in the public doman.
    JIMSPAGE.CO.NZ


    This is just a basic demo for interfacing a pot to the "Simconnect Inputs" page. (Not in the 'Experts' section.)
    Codes C56 thru to C65 require the span to be 0 to 100 percent for the inputs that require a pot.
    It's not good code but it works. (Also look at the code in the link below)


    For pot inputs for the 'Experts' section the range is generally 0 to 16383
    There are some very good codes for that range here,,,,
    http://www.mycockpit.org/forums/showthread.php?t=27995


    Have fun.


    */
    const int analogInPin = A0; // Analog input pin that the potentiometer wiper is attached to
    int sensorValue = 0; // value read from the pot
    int sensorValueOld = 55;
    long previousMillis = 0;


    void setup() {
    Serial.begin(115200);
    }


    void loop() {
    //set up the analog read delay
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > 33) { // fiddle the 33 to suit time delay/speed
    previousMillis = currentMillis;
    // Lets read the analog in value:
    sensorValue = analogRead(analogInPin);
    // Now lets see if it's different
    if (sensorValueOld > (sensorValue + 1) || sensorValueOld < (sensorValue - 1)){ // gets rid of "flutter"
    Serial.print("C56"); // change the "C56" to suit your Link2fs slot
    int sensorValueX = map(sensorValue,0,1023,0,100); // use this line for throttles etc. (0 to 100)
    //int sensorValueX = map(sensorValue,0,1023,-100,100); // <<< Use this line for trim. (-100 to 100)
    Serial.println(long(sensorValueX));
    sensorValueOld = sensorValue;
    }// end of "yes it's different" loop
    }// end of timed loop
    } // end of void loop







    It worked nicely, but only with the left one, i tried diferent ways to add the "C57" to another line, but it was printing in the same line.



    I have the felling that i'm struggling with something very easy to deal, but anyways, i'll be happy to get some help!!!

  2. #2
    25+ Posting Member


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    63
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: link2fs throttle

    Happy New Year.

    Each throttle needs its own analog pin, control and storage variables, and code. You are on the right track.
    Have a look at this. Taken from a longer sketch, it compiles but not tested.
    It is a little clearer if you use the auto format tool.


    //THROTTLE QUADRANT
    long throttle_slot, propeller_slot, mixture_slot, rudder_slot;
    const byte throttle_pin = 0;
    const byte propeller_pin = 1;
    const byte mixture_pin = 2;
    int throttle_low = 0; int throttle_high = 1023; // set if using rotary potentiometer with restricted rotation
    int propeller_low = 0; int propeller_high = 1023;
    int mixture_low = 0; int mixture_high = 1023;


    void setup(){
    Serial.begin(115200);
    }// end void setup()


    void loop() {
    // NOTE 'propeller_slot = millis() + 1000;' stops loop() from running the code continuously until propeller_slot is assigned by next throttle line
    if (millis() > throttle_slot){THROTTLE(); propeller_slot = millis() + 10; throttle_slot = millis() + 40;}
    if (millis() > propeller_slot){PROPELLER(); propeller_slot = millis() + 1000; mixture_slot = millis() + 10;}
    if (millis() > mixture_slot){MIXTURE(); mixture_slot = millis() + 1000;}
    }// end void loop()


    void THROTTLE(){
    int firstRead, throttle_percent;
    static int throttle_oldPercent;
    firstRead = analogRead(throttle_pin);
    throttle_percent = map(firstRead, throttle_low, throttle_high, 0, 100);
    if ((throttle_percent + 1 < throttle_oldPercent) || (throttle_percent - 1 > throttle_oldPercent)){
    String tempString = String(throttle_percent);
    while (tempString.length() < 3) tempString = '0' + tempString;
    Serial.println("C56" + tempString);
    throttle_oldPercent = throttle_percent;
    }
    }

    void PROPELLER(){
    int firstRead, propeller_percent;
    static int propeller_oldPercent;
    firstRead = analogRead(propeller_pin);
    propeller_percent = map(firstRead, propeller_low, propeller_high, 0, 100);
    if ((propeller_percent + 1 < propeller_oldPercent) || (propeller_percent - 1 > propeller_oldPercent)){
    String tempString = String(propeller_percent);
    while (tempString.length() < 3) tempString = '0' + tempString;
    Serial.println("C58" + tempString);
    propeller_oldPercent = propeller_percent;
    }
    }
    void MIXTURE(){
    int firstRead, mixture_percent;
    static int mixture_oldPercent;
    firstRead = analogRead(mixture_pin);
    mixture_percent = map(firstRead, mixture_low, mixture_high, 0, 100);
    if ((mixture_percent + 1 < mixture_oldPercent) || (mixture_percent - 1 > mixture_oldPercent)){
    String tempString = String(mixture_percent);
    while (tempString.length() < 3) tempString = '0' + tempString;
    Serial.println("C60" + tempString);
    mixture_oldPercent = mixture_percent;
    }
    }// end MIXTURE()

    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  3. #3
    New Member
    Join Date
    Dec 2017
    Location
    USA
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: link2fs throttle

    It Worked!! Thank You!!

  4. #4
    25+ Posting Member


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    63
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: link2fs throttle

    I did not answer your question fully. For a twin, double up on analog pins, double up on most variables - eg. use throttle_percentLeft and throttle_percentRight, double up on block of code for each function. I don't which works best, left engine analogs 0, 1, & 2, or stagger the pins, analogs 0, 2, & 4, but the analog to digital convertor (ADC) requires a short time to settle down while switching immediately from one analog pin to another. Complete the process for analog pin #1. Before running the process for analog pin #2, do an empty analog read on analog pin #2, then read analog pin #2.
    eg.
    firstRead = analogRead(throttle_pinLeft);
    do the conversion for the left throttle and pass the instruction to FS via USB
    analogRead(throttle_pinRight);
    firstRead = analogRead(throttle_pinRight);
    do the conversion for the right throttle and pass the instruction to FS via USB

    If my sim ever gets far enough along that the flight yoke can sit in the limited space occupied by the keyboard, the present slide potentiometers used for push type throttle quadrant will be monitored by the flight yoke controller. IF there is no firmware fix for the wide null in its programming, that controller will be replaced by an Arduino programmed board - Leonardo or Pro Micro.

    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  5. #5
    New Member
    Join Date
    Dec 2017
    Location
    USA
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: link2fs throttle

    Yeah, i was actually trying to Control Both Throttle's on a default 737-8 using one single potentiometer, so i based on what you said about each throttle having its own analog pin, control and storage variables. Then i just added three more variables(sensorValueold1, sensorValue1 and previousMillis1), which i just increased by "1"(lack of creativity).
    Then i simply copy+paste the code for one throttle with the new variables and maintained the analog input of the potentiometer for both code lines


    the result is this:


    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > 33) { // fiddle the 33 to suit time delay/speed
    previousMillis = currentMillis;
    sensorValue = analogRead(analogInPin);
    if (sensorValueOld > (sensorValue + 1) || sensorValueOld < (sensorValue - 1)){ // gets rid of "flutter"
    Serial.print("C56"); // change the "C56" to suit your Link2fs slot
    int sensorValueX = map(sensorValue,0,350,0,100); // use this line for throttles etc. (0 to 100)
    Serial.println(long(sensorValueX));
    sensorValueOld = sensorValue;



    }// end of "yes it's different" loop
    }// end of timed loop













    unsigned long currentMillis1 = millis();
    if(currentMillis - previousMillis1 > 33) { // fiddle the 33 to suit time delay/speed
    previousMillis1 = currentMillis;
    // Lets read the analog in value:
    sensorValue1 = analogRead(analogInPin);
    // Now lets see if it's different
    if (sensorValueOld1 > (sensorValue1 + 1) || sensorValueOld1 < (sensorValue1 - 1)){ // gets rid of "flutter"
    Serial.print("C57"); // change the "C56" to suit your Link2fs slot
    int sensorValueY = map(sensorValue1,0,350,0,100); // use this line for throttles etc. (0 to 100)
    Serial.println(long(sensorValueY));
    sensorValueOld1 = sensorValue1;
    }
    }

  6. #6
    25+ Posting Member


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    63
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: link2fs throttle

    Good job.

    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013