Results 1 to 5 of 5
  1. #1
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Multiple Led's for Fsx

    Hey guys was wondering if anyone had a quick minute to explain to me what im doing wrong, i have a sketch for all my Autopilot Leds but for some reason there first If argument is the only one that works, i know all the Leds are hooked up correctly cause if i change the OUTPUT argument to suit every single one they all light up, im guessing its just somthing im not putting in between each IF, any help at all would rok guys!

    code:

    [/code

    int xx;
    String ap, apold, loc, locold, athr, athrold, alt, altold, apr, aprold;
    void setup() {
    //int APSwitch = A1; // Connected Flight Director Switches (A0)
    //int AP2Switch = A2; // Connected Auto Throttle Switch (A1)
    //int ALTSwitch = A3; // Connected to GPS vs NAV Switch (A2)
    //int ILSSwitch = A4; // Connected Flight Director Switches (A0)
    //int APTHRSwitch = A5;
    //int LOCSwitch = A6;// Connected Auto Throttle Switch (A1)
    //int APPRSwitch = A7; // Connected to GPS vs NAV Switch (A2)
    pinMode(33,OUTPUT);//AP
    pinMode(31,OUTPUT);//AP2
    pinMode(29,OUTPUT);//ILS
    pinMode(27,OUTPUT);//LOC
    pinMode(39, OUTPUT);//ATHR
    pinMode(35, OUTPUT);//ALT
    pinMode(41, OUTPUT);//APP
    //pinMode(APSwitch, INPUT);
    // pinMode(AP2Switch, INPUT);
    // pinMode(ALTSwitch, INPUT);
    // pinMode(ILSSwitch, INPUT);
    // pinMode(LOCSwitch, INPUT);
    // pinMode(APTHRSwitch, INPUT);
    //digitalWrite(APSwitch, HIGH);
    //digitalWrite(APPRSwitch, HIGH);
    Serial.begin(115200);
    }
    void loop() {
    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx == 'b'){
    delay (11);
    ap = "";
    ap += (char)Serial.read();
    if (ap != apold){
    if (ap == "0") {digitalWrite(33, LOW);}
    if (ap == "1") {digitalWrite(33, HIGH);} {

    apold = ap;






    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx == 'x'){
    delay (11);
    loc = "";
    loc += (char)Serial.read();
    loc += (char)Serial.read();
    loc += (char)Serial.read();
    if (loc != locold){
    if (loc == "0") {digitalWrite(27, LOW);}
    if (loc == "1") {digitalWrite(27, HIGH);}

    locold = loc;

    }



    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx == 'E'){
    delay (11);
    athr = "";
    athr += (char)Serial.read();
    if (athr != athrold){
    if (athr == "0") {digitalWrite(39, LOW);}
    if (athr == "1") {digitalWrite(39, HIGH);}

    athrold = athr;

    }
    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx == 's'){
    delay (11);
    alt = "";
    alt += (char)Serial.read();
    if (alt != apold){
    if (alt == "0") {digitalWrite(35, LOW);}
    if (alt == "1") {digitalWrite(35, HIGH);}

    altold = alt;

    }
    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx== 'v'){
    delay (11);
    apr = "";
    apr += (char)Serial.read(); //Read the first charactor sent
    if (apr != aprold){
    if (apr == "0") {digitalWrite(41, LOW);}
    if (apr == "1") {digitalWrite(41, HIGH);} {
    aprold = apr;

    }

    delay(50);
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }

    }
    }
    }
    }

    /code]

  2. #2
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple Led's for Fsx

    Gosh man cant even post the code properly lol ....

  3. #3
    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: Multiple Led's for Fsx

    Kia ora! MadMaori ,, I was kind of hoping one of the other guys may have popped in here as C is not one of my "fun" languages.

    One thing I spotted was you never had the proper sequence of "blocks" in your code. What should happen is this ,,

    Check if there is anything in the com buffer ,,,
    If there is ,, read 1 character ,,,
    If that character is 'x' then do something ,,,
    If that character is 'E' then do something ,,,
    If that character is 's' then do something ,,,
    If that character is 'v' then do something ,,,


    So with that 1 character ,, it checks the whole lot until it finds a match.

    I had a quick play with your code and came up with this ,,,,

    int xx;
    String ap, apold, loc, locold, athr, athrold, alt, altold, apr, aprold;
    void setup() {
      //int APSwitch = A1; // Connected Flight Director Switches (A0)
      //int AP2Switch = A2; // Connected Auto Throttle Switch (A1)
      //int ALTSwitch = A3; // Connected to GPS vs NAV Switch (A2)
      //int ILSSwitch = A4; // Connected Flight Director Switches (A0)
      //int APTHRSwitch = A5;
      //int LOCSwitch = A6;// Connected Auto Throttle Switch (A1)
      //int APPRSwitch = A7; // Connected to GPS vs NAV Switch (A2)
      pinMode(33,OUTPUT);//AP
      pinMode(31,OUTPUT);//AP2
      pinMode(29,OUTPUT);//ILS
      pinMode(27,OUTPUT);//LOC
      pinMode(39, OUTPUT);//ATHR
      pinMode(35, OUTPUT);//ALT
      pinMode(41, OUTPUT);//APP
      //pinMode(APSwitch, INPUT);
      // pinMode(AP2Switch, INPUT);
      // pinMode(ALTSwitch, INPUT);
      // pinMode(ILSSwitch, INPUT);
      // pinMode(LOCSwitch, INPUT);
      // pinMode(APTHRSwitch, INPUT);
      //digitalWrite(APSwitch, HIGH);
      //digitalWrite(APPRSwitch, HIGH);
      Serial.begin(115200);
    }
    void loop() {
      if (Serial.available() > 0) { // only do this once ,, at the start
        xx = Serial.read(); // read 1 caracter from the buffer

        if (xx == 'b'){ // if it's 'b' then do the following ,,,
          delay (11);
          ap = ""; // makes the AP string "nothing"
          ap += char(Serial.read()); // reads a caractor and "adds" it to the AP string
          if (ap != apold){ // checks if it's different from the "old" (last) reading
            if (ap == "0") {
              digitalWrite(33, LOW);
            } 
            else {
              digitalWrite(33, HIGH);
            }
            apold = ap; // updates the "old" string with the "new" status
          } // end of the "yes it's different to the old reading" sequence
        } // end of "found the AP" sequence

        if (xx == 'x'){ // if it's x then do the following ,,,
          delay (11);
          loc = "";
          loc += char(Serial.read());
          loc += char(Serial.read());
          loc += char(Serial.read());
          if (loc != locold){
            if (loc == "0") {
              digitalWrite(27, LOW);
            }
            if (loc == "1") {
              digitalWrite(27, HIGH);
            }
            locold = loc;
          }
        }


        if (xx == 'E'){ // if it's E then do the following ,,,,
          delay (11);
          athr = "";
          athr += char(Serial.read());
          if (athr != athrold){
            if (athr == "0") {
              digitalWrite(39, LOW);
            }
            if (athr == "1") {
              digitalWrite(39, HIGH);
            }
            athrold = athr;
          }
        }

        if (xx == 's'){ // if it's s then do the following
          delay (11);
          alt = "";
          alt += char(Serial.read());
          if (alt != apold){
            if (alt == "0") {
              digitalWrite(35, LOW);
            }
            if (alt == "1") {
              digitalWrite(35, HIGH);
            }
            altold = alt;
          }
        }

        if (xx== 'v'){ // if its v then do the following
          delay (11);
          apr = "";
          apr += char(Serial.read()); //Read the first charactor sent
          if (apr != aprold){
            if (apr == "0") {
              digitalWrite(41, LOW);
            }
            if (apr == "1") {
              digitalWrite(41, HIGH);
            } 
            aprold = apr;

          } // end of the "yes it's different to the old reading" sequence
        }  // end of "found the apr" sequence
        delay(50);
      }  // end of "Yes" there is a serial read.
    }  // end of main loop (It goes back to the start of the main loop)





    I used Arduino V1
    It compiles.
    I never checked if it actually ran as the whole idea was to demonstrate the "blocks" that you never had.

    Hope that helps ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  4. #4
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple Led's for Fsx

    Quote Originally Posted by Jim NZ View Post
    Kia ora! MadMaori ,, I was kind of hoping one of the other guys may have popped in here as C is not one of my "fun" languages.

    One thing I spotted was you never had the proper sequence of "blocks" in your code. What should happen is this ,,

    Check if there is anything in the com buffer ,,,
    If there is ,, read 1 character ,,,
    If that character is 'x' then do something ,,,
    If that character is 'E' then do something ,,,
    If that character is 's' then do something ,,,
    If that character is 'v' then do something ,,,


    So with that 1 character ,, it checks the whole lot until it finds a match.

    I had a quick play with your code and came up with this ,,,,






    I used Arduino V1
    It compiles.
    I never checked if it actually ran as the whole idea was to demonstrate the "blocks" that you never had.

    Hope that helps ,,, Jim
    Bro you have no idea how happy i am right now lol, all this started as a pipe dream one day when i saw your website and now i basically have a full size A340 cockpit in my lounge lmao and just like ur wife mine still loves me omg lol, thnx so much for your help bruv, im sure as i learn a lil bit each week i will eventually be able to do it all myself, **** maybe even adjuest your link2fs to *** a few xtra things like 4 engine N1 lights etc, oh the mind boggles at the possibilities , jim thank you again you are a gentlemen and a scholar!!!

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

    Re: Multiple Led's for Fsx

    K time to take out the // in my code for the switches and see where that takes me lol!

    Whoa u know what would really be cool?, adding the master alarm flasher as i have one already in place but the light dosnt light up i just use it to shut the master alarm up lol ...