Results 1 to 5 of 5
  1. #1
    New Member
    Join Date
    May 2016
    Location
    Poland
    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

    Arduino - gear and flaps servo together problem

    Hello
    I'm a novice programmer and fan FSX, I have a problem with a combination of two codes separately,
    showcases work but after gluing does not work. working gear up / down flap or not they work together.
    Can you help me fix this code, after finishing my cocpit i'll show my job.
    Thank you very much . I send my codes
    I still have the possibility of connecting the servo trim servo trotlle ect.
    I'm not sure but it may need to do two separate loops, but I tried not coming out

    Thank you very much for your help
    . I send my codes
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    May 2016
    Location
    Poland
    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: Arduino - gear and flaps servo together problem

    I modified my code . However, further something is not working, is there anyone who can help me , for the good of all .
    Thank you

    this is code



    /*
    This code is in the public domain
    For use with "Link2fs_Multi" (FSX or FS9)
    Jimspage.co.nz
    My thanks to the Guys that gave me snippets of code.

    This sets the Arduino Mega card to indicate gear position and flaps, using simconnect codes with
    the remainder for inputs except pin 13.
    LED for nose gear down onto pin 2 (Thru a resistor)
    LED for left gear down onto pin 3 (Thru a resistor)
    LED for right gear down onto pin 4 (Thru a resistor)
    LED for nose gear in transition onto pin 5 (Thru a resistor)
    LED for left gear in transition onto pin 6 (Thru a resistor)
    LED for right gear in transition onto pin 7 (Thru a resistor)
    LED for Flaps not fully up onto pin 8 (Thru a resistor)
    LED for Flasps down onto pin 9 (Thru a resistor)

    For the gear control, attach 2 buttons (or a double throw toggle switch) to pins 10 and 11
    A button on pin 12 will raise the flaps 1 notch
    A button on pin 14 will lower the flaps 1 notch

    You need to tick "?Y" in "Link2fs_Multi" down the bottom of "systems2". (Extractions2 tab).
    Also you need to tick " Attach a button to any pin, 15 upwards and program that pin in "Keys" section or the direct inputs section.
    Everything to do with "Keys" starts with a "K" in this code.

    Mega users ,,, so you can use all the extra pins as inputs ,, change the following ,,,
    Line 54, change the 19 to 69
    Line 121, change the 19 to 69
    */

    #include // Biblioteca para controlar servo motor
    String entrada,dados;
    char tipo,direcao;
    Servo servo1;
    int pos,elimina,i;
    int valor_flap,flap;




    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;

    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
    String gearSimple, flaps, flapsOld;

    void setup()
    {
    servo1.attach(A3); //Flaps

    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
    // Lets set the output pin modes (longhand)
    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 fully Up LED
    pinMode(9, OUTPUT); // Flaps down LED
    // now we will do all the inputs in a routine ,,,
    for (int KoutPin = 10; KoutPin <= 69; KoutPin++)// Get all the pins ready for simconnect codes and "Keys"(all inputs)
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    }

    void loop() {
    {INPUTS();} //Check the Simconnect and "keys" section for any input pins
    if (Serial.available()) {//checks the serial read buffer
    CodeIn = getChar();// reads one charactor via it's own routine (char getChar)
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<", goto LESSTHAN void
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?", goto QUESTION void
    }//end of yes there is something to read
    } // 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


    while (Serial.available() > 0) {
    delay(10);
    elimina = char(Serial.read()); //Para versão nova do Link2fs
    tipo=char(Serial.read());
    switch (tipo){

    case 'G':
    //Flaps
    //digitalWrite(led, LOW);
    //delay(10);
    entrada= "";
    for( i = 0; i < 3; i++){
    entrada += char(Serial.read());
    }
    valor_flap = entrada.toInt();
    switch (valor_flap){
    case 0: flap = 179;
    break;
    case 1: flap = 159;
    break;
    case 3: flap = 139;
    break;
    case 7: flap = 119;
    break;
    case 14: flap = 99;
    break;
    case 21: flap = 79;
    break;
    case 36: flap = 62;
    break;
    case 43: flap = 44;
    break;
    case 57: flap = 19;
    break;
    default:
    break;
    }
    valor_flap=map(flap,0,57,20,180);
    servo1.write(flap);
    break;
    default: break;
    }

    }


    }// end of getchar void.

    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get the second identifier
    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 flapsINT = flaps.toInt(); // convert it to an integer (Thanks Phill)
    if (flapsINT > 0){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);}//action the LED
    if (flapsINT > 20){digitalWrite(9, HIGH);}else{digitalWrite(9, LOW);}//action the LED
    break;
    }// end of switch
    }// 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

    void INPUTS(){ // Simconnect codes and "Keys" section
    Kstringnewstate = "";
    for (int KpinNo = 10; KpinNo <=19; KpinNo++){ //set this to the input pins. (pins 10 to 19)
    KpinStateSTR = String(digitalRead(KpinNo)); //read the state of the pin
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 10));// gets the 'old' state of the pin from string
    if (KpinStateSTR != KoldpinStateSTR){// checks if it's different to the last reading of that pinNo
    if (KpinNo != 13){ // avoid using pin 13 as an input unless you know the tricks.
    if (KpinNo == 10 && KpinStateSTR == "0"){Serial.println ("C01");} //sets gear handle up
    if (KpinNo == 11 && KpinStateSTR == "0"){Serial.println ("C02");} //sets gear handle down
    if (KpinNo == 12 && KpinStateSTR == "0"){Serial.println ("C15");} //Decrements flap handle position
    if (KpinNo == 14 && KpinStateSTR == "0"){Serial.println ("C14");} //Increments flap handle position
    // Add more here but remember to also change the figure in the next line down. (the 14)
    // now the "Keys" bit ,,,
    if (KpinNo > 14){ //Change pinNo number to same as the highest one used for simconnect codes.(the 14)
    Serial.print ("D");
    if (KpinNo < 10) Serial.print ("0");
    Serial.print (KpinNo);
    Serial.println (KpinStateSTR);
    }//end of 'its pinNo is greater than 14'
    }//end of 'its not pin 13'
    }//end of 'its different'
    Kstringnewstate += KpinStateSTR;
    }//end of 'for' loop (read the pins)
    Kstringoldstate = Kstringnewstate;
    }//end of INPUTS void

  3. #3
    New Member
    Join Date
    May 2016
    Location
    Poland
    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: Arduino - gear and flaps servo together problem

    I modified my code . However, further something is not working, is there anyone who can help me , for the good of all .
    Thank you



    /*
    This code is in the public domain
    For use with "Link2fs_Multi" (FSX or FS9)
    Jimspage.co.nz
    My thanks to the Guys that gave me snippets of code.

    This sets the Arduino Mega card to indicate gear position and flaps, using simconnect codes with
    the remainder for inputs except pin 13.
    LED for nose gear down onto pin 2 (Thru a resistor)
    LED for left gear down onto pin 3 (Thru a resistor)
    LED for right gear down onto pin 4 (Thru a resistor)
    LED for nose gear in transition onto pin 5 (Thru a resistor)
    LED for left gear in transition onto pin 6 (Thru a resistor)
    LED for right gear in transition onto pin 7 (Thru a resistor)
    LED for Flaps not fully up onto pin 8 (Thru a resistor)
    LED for Flasps down onto pin 9 (Thru a resistor)

    For the gear control, attach 2 buttons (or a double throw toggle switch) to pins 10 and 11
    A button on pin 12 will raise the flaps 1 notch
    A button on pin 14 will lower the flaps 1 notch

    You need to tick "?Y" in "Link2fs_Multi" down the bottom of "systems2". (Extractions2 tab).
    Also you need to tick " Attach a button to any pin, 15 upwards and program that pin in "Keys" section or the direct inputs section.
    Everything to do with "Keys" starts with a "K" in this code.

    Mega users ,,, so you can use all the extra pins as inputs ,, change the following ,,,
    Line 54, change the 19 to 69
    Line 121, change the 19 to 69
    */

    #include // Biblioteca para controlar servo motor
    String entrada,dados;
    char tipo,direcao;
    Servo servo1;
    int pos,elimina,i;
    int valor_flap,flap;




    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;

    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
    String gearSimple, flaps, flapsOld;

    void setup()
    {
    servo1.attach(A3); //Flaps

    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
    // Lets set the output pin modes (longhand)
    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 fully Up LED
    pinMode(9, OUTPUT); // Flaps down LED
    // now we will do all the inputs in a routine ,,,
    for (int KoutPin = 10; KoutPin <= 69; KoutPin++)// Get all the pins ready for simconnect codes and "Keys"(all inputs)
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    }

    void loop() {
    {INPUTS();} //Check the Simconnect and "keys" section for any input pins
    if (Serial.available()) {//checks the serial read buffer
    CodeIn = getChar();// reads one charactor via it's own routine (char getChar)
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<", goto LESSTHAN void
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?", goto QUESTION void
    }//end of yes there is something to read
    } // 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


    while (Serial.available() > 0) {
    delay(10);
    elimina = char(Serial.read()); //Para versão nova do Link2fs
    tipo=char(Serial.read());
    switch (tipo){

    case 'G':
    //Flaps
    //digitalWrite(led, LOW);
    //delay(10);
    entrada= "";
    for( i = 0; i < 3; i++){
    entrada += char(Serial.read());
    }
    valor_flap = entrada.toInt();
    switch (valor_flap){
    case 0: flap = 179;
    break;
    case 1: flap = 159;
    break;
    case 3: flap = 139;
    break;
    case 7: flap = 119;
    break;
    case 14: flap = 99;
    break;
    case 21: flap = 79;
    break;
    case 36: flap = 62;
    break;
    case 43: flap = 44;
    break;
    case 57: flap = 19;
    break;
    default:
    break;
    }
    valor_flap=map(flap,0,57,20,180);
    servo1.write(flap);
    break;
    default: break;
    }

    }


    }// end of getchar void.

    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get the second identifier
    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 flapsINT = flaps.toInt(); // convert it to an integer (Thanks Phill)
    if (flapsINT > 0){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);}//action the LED
    if (flapsINT > 20){digitalWrite(9, HIGH);}else{digitalWrite(9, LOW);}//action the LED
    break;
    }// end of switch
    }// 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

    void INPUTS(){ // Simconnect codes and "Keys" section
    Kstringnewstate = "";
    for (int KpinNo = 10; KpinNo <=19; KpinNo++){ //set this to the input pins. (pins 10 to 19)
    KpinStateSTR = String(digitalRead(KpinNo)); //read the state of the pin
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 10));// gets the 'old' state of the pin from string
    if (KpinStateSTR != KoldpinStateSTR){// checks if it's different to the last reading of that pinNo
    if (KpinNo != 13){ // avoid using pin 13 as an input unless you know the tricks.
    if (KpinNo == 10 && KpinStateSTR == "0"){Serial.println ("C01");} //sets gear handle up
    if (KpinNo == 11 && KpinStateSTR == "0"){Serial.println ("C02");} //sets gear handle down
    if (KpinNo == 12 && KpinStateSTR == "0"){Serial.println ("C15");} //Decrements flap handle position
    if (KpinNo == 14 && KpinStateSTR == "0"){Serial.println ("C14");} //Increments flap handle position
    // Add more here but remember to also change the figure in the next line down. (the 14)
    // now the "Keys" bit ,,,
    if (KpinNo > 14){ //Change pinNo number to same as the highest one used for simconnect codes.(the 14)
    Serial.print ("D");
    if (KpinNo < 10) Serial.print ("0");
    Serial.print (KpinNo);
    Serial.println (KpinStateSTR);
    }//end of 'its pinNo is greater than 14'
    }//end of 'its not pin 13'
    }//end of 'its different'
    Kstringnewstate += KpinStateSTR;
    }//end of 'for' loop (read the pins)
    Kstringoldstate = Kstringnewstate;
    }//end of INPUTS void

  4. #4
    New Member
    Join Date
    May 2016
    Location
    Poland
    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: Arduino - gear and flaps servo together problem

    Hello
    I was able to connect the two codes and convert into my needs .
    Attached ready code .
    Subject close
    Attached Files Attached Files

  5. Likes BushPilotWannabe liked this post
  6. #5
    10+ Posting Member
    Join Date
    Feb 2009
    Location
    UK
    Posts
    21
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino - gear and flaps servo together problem

    There is much good work going on over here:
    http://phpjj.freeforums.org/pmdg-dat...rduino-f6.html