Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    25+ Posting Member
    Join Date
    Jul 2012
    Location
    pt
    Posts
    66
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    need advice on code for flaps position

    hi guys
    imagine this:
    instead of having a servo or something similar to make a indicator of the flap positition like the boeing 737 i was thinking if it was possible to have a led turn on when the flap reached a position for example if i chose flaps 1 a led would turn on and then when i chose flaps 10 another led turn on. that way i could see what is the current flap position. i think it would be simpler than buying the servo and making the gauge in that way i would only need a few leds in my panel and some stickers made to show the position number. is it possible? can anyone help me?

  2. #2
    Executive Assistant Geremy Britton's Avatar
    Join Date
    Jul 2007
    Location
    North,East England
    Posts
    1,597
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: need advice on code for flaps position

    That is certainly doable. You would need a phidgets card and considering the price of these compared to the guage it may not work out too much cheaper to be honest. Let me know how you go.

    Thanks
    Geremy Britton
    Executive Assistant, MyCockpit Inc
    Head of GLB Flight Products
    www.geremy.co.uk

  3. #3
    25+ Posting Member
    Join Date
    Jul 2012
    Location
    pt
    Posts
    66
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: need advice on code for flaps position

    i'm sorry but i meant using an arduino mega. phidgets card would be to expensive for a hobbyist like me... maybe someone could have an idea in how to do that. thanks anyway

  4. #4
    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: need advice on code for flaps position

    Pirata,
    As Geremy correctly stated, it is certainly doable. Additionally, it's super simple. Which version of Jim's software are you using? Do you currently have code for your Mega? If so, post it so I can better know how to assist you. This weekend is rapidly shaping up to be busy so I hope to provide some guidance by mid-week.
    -James

  5. #5
    25+ Posting Member
    Join Date
    Jul 2012
    Location
    pt
    Posts
    66
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: need advice on code for flaps position

    hi there jmeller
    thank you very much for your help i really apreciate it. at this time i have no code but i'm inclined to use jims multi software, i think the flpas extraction that jim did is for a servo is it not? if so its probably impossible to do what i want with jims fantastic piece of software...

  6. #6
    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: need advice on code for flaps position

    No prob. Jim's software simply extracts information from the simulator and pushes it into the arduino (if instructed to do so). After the arduino has possession of the data, it is totally up to you how to handle it. If you want to instruct the arduino to drive a servo, you can. If you want it to drive LEDs, you can. Think of it as a blank canvas to paint your simulator creation.

    Go ahead and upload one of Jim's sample INOs into the arduino. Write a few lines of code which state - if Nav1 freq = "109.250" then turn on LED1 else turn LED1 off. The same principle will apply to flaps indicator.

    Pretty easy, huh?

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

    Re: need advice on code for flaps position

    Try this i just took from multi 5c example. compare what i did to the example by jim (Flap servo code) and test to see if it works. im new to programming someone else can verify that this is fine but just use basic knowledge and u will be ok. U may have to change the "3" and "7" for flap position. run fsx look at what multi is showing when u select flap position and change to the value u need.


    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;
    String flaps, flapsOld;


    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;


    void setup()
    {
    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    for (int KoutPin = 2; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    pinMode(2, OUTPUT);// flap pos 1
    digitalWrite(2, LOW);
    pinMode(3, OUTPUT);// flap pos 2
    digitalWrite(3, LOW);

    }


    void loop() {
    {KEYS();} //Check the "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)
    }


    }


    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }


    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }


    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'G'://Found the second identifier ("G" Flaps position)
    flaps = "";
    flaps += getChar();
    flaps += getChar();
    flaps += getChar();
    if(flaps != flapsOld){
    if(flaps == "3"){
    digitalWrite(2, HIGH);


    }
    else{

    digitalWrite(2, LOW);
    }

    if(flaps == "7") {
    digitalWrite(3, HIGH);
    }
    else{
    digitalWrite(3, LOW);
    }
    machIasOld = machIas;





    break;
    }
    }


    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }
    void SLASH(){ // The first identifier was "/" (Annunciator)
    //Do something
    }
    void KEYS()
    {
    Kstringnewstate = "";
    for (int KpinNo = 2; KpinNo < 70; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 2));
    if (KpinStateSTR != KoldpinStateSTR)
    {
    if (KpinNo != 13){
    Serial.print ("D");
    if (KpinNo < 10) Serial.print ("0");
    Serial.print (KpinNo);
    Serial.println (KpinStateSTR);
    }
    }
    Kstringnewstate += KpinStateSTR;
    }
    Kstringoldstate = Kstringnewstate;
    }

  8. #8
    25+ Posting Member
    Join Date
    Jul 2012
    Location
    pt
    Posts
    66
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: need advice on code for flaps position

    thanks jmeller you've been great help and i do apologize for my newby questions. i'll try what you've said tomorow. best regards

  9. #9
    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: need advice on code for flaps position

    Thanks, MLRUSSELL; your example should give him a good start.
    Pirata, no need to apologize. We all must start from somewhere.

    MLRUSSELL is correct:
    1.) verify you have the flaps checked on the Multi
    2.) note the value (from the Multi) at each flap setting
    3.) code your flap LED qualifier for each setting to digitalWrite a unique output HIGH;
    4.) if the flap setting does not equal your qualifier, make sure to digitalWrite the unique output LOW
    That's pretty much it.

    If you have any more questions, feel free to post them. I'm certain MLRUSSEL, myself, or others can help you get your wheels off the ground fairly quickly.

  10. #10
    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: need advice on code for flaps position

    OK ,, now I can get back into this site ,,, pirata ,, for something really simple this thread has got awfully complicated.
    Sometimes , for that first step ,, it just takes a simple example to get you going.

    MLRUSSELL's code has a few problems with it so it's not a good example to get started on ,, I have added a code for you below.

    I understand you are using the "Multi" ,,, and also that you don't need provision for any inputs from the Arduino to FSX.
    I took the sample "Multi_Keys_GearSimple_Simconnect" (it's in your download) and stripped it of everything that was not necessary for what you want to do.
    To move forward from here ,, just compare what is below to the original code.

    I threw in a void to suit the flaps extraction but left the gear extractions in there as you'll probably want them at anyrate ,, if not ,, just delete it.
    This has been tested.

    Note that for the flaps I use it's figure as an integer (not as a string) to make the "happenings" ,, this is because using strings to compare for a trigger point is very risky on a fast changing string ,, if not imposable.



    /*
    This code is in the public domain
    For use with "Link2fs_Multi_ beta5c"
    Jimspage.co.nz
    My thanks to the Guys that gave me snippets of code.

    This sets the Arduino Mega card to indicate gear and flaps position
    LED's (green) for gear onto pin's 2,3,4 (Thru a resistors)
    LED's for gear's in transition onto pin 5,6,7 (Thru a resistors)
    LED's for flap position onto pin 8,9,10 (Thru a resistors)
    You need to tick "?Y" (gear simple)in "Link2fs_Multi". (It's down the bottom of systems2)
    You need to tick "

    */


    int CodeIn;// used on all serial reads
    String gearSimple;
    String flaps;

    void setup()
    {
    pinMode(2, OUTPUT); // gear nose LED
    pinMode(3, OUTPUT); // gear left LED
    pinMode(4, OUTPUT); // gear right LED
    pinMode(5, OUTPUT); // gear nose in transition LED
    pinMode(6, OUTPUT); // gear left in transition LED
    pinMode(7, OUTPUT); // gear right in transition LED
    pinMode(8, OUTPUT); // flaps "not up" LED
    pinMode(9, OUTPUT); // flaps 1st position LED
    pinMode(10, OUTPUT); // flaps 2nd position LED
    // you could put the "digitalWrites(?,LOW)" here too but in this case they are not nessecary.
    Serial.begin(115200);
    }

    void loop() {
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    }
    } // end of void loop (The main one)

    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.

    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'G'://Found the second identifier ("G" Flaps position)
    flaps = "";
    flaps += getChar();
    flaps += getChar();
    flaps += getChar();
    int flapsi = flaps.toInt(); // convert it to an integer (Thanks Phill)
    if (flapsi > 0) {digitalWrite(8, HIGH);} else {digitalWrite(8, LOW);}
    if (flapsi > 10) {digitalWrite(9, HIGH);} else {digitalWrite(9, LOW);}//you may have to adjust the '10'
    if (flapsi > 30) {digitalWrite(10, HIGH);} else {digitalWrite(10, LOW);}//you may have to adjust the '30'
    break;
    }
    }//end of LESSTHAN void

    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get the second identifier
    switch(CodeIn) {// Now lets find what to do with it
    case 'Y': // found the second identifier (the "Gear simple")
    gearSimple = "";
    gearSimple += getChar();// get first charactor (Nose gear)
    if (gearSimple == "2"){digitalWrite(2, HIGH);}else{digitalWrite(2, LOW);}
    if (gearSimple == "1"){digitalWrite(5, HIGH);}else{digitalWrite(5, LOW);}
    gearSimple += getChar(); // get the second charactor (gear left)
    if (gearSimple.endsWith("2")){digitalWrite(3, HIGH);}else{digitalWrite(3, LOW);}
    if (gearSimple.endsWith("1")){digitalWrite(6, HIGH);}else{digitalWrite(6, LOW);}
    gearSimple += getChar(); // get the third charactor (gear right)
    if (gearSimple.endsWith("2")){digitalWrite(4, HIGH);}else{digitalWrite(4, LOW);}
    if (gearSimple.endsWith("1")){digitalWrite(7, HIGH);}else{digitalWrite(7, LOW);}
    break;
    }
    }// end of question void







    Copying this over chopped off "You need to also tick "flaps" in the Mutli

    Have a play and see how you go ,,, Jim
    Last edited by Jim NZ; 07-21-2013 at 01:13 AM.
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

Page 1 of 2 12 LastLast