Results 1 to 6 of 6
  1. #1
    25+ Posting Member



    Join Date
    Aug 2009
    Location
    Oss - Netherlands
    Posts
    61
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    gearpanel with code

    Hi all,

    I have made a gearpanel to control the gear.
    Its basically a panel with an on/off switch to lower/raise the gear and 3 green leds + 1 red led.
    It is based on the starter kit from Jims PDE starter kit. and uses the Link2Fsv4 program.

    I am by no means an arduino expert, but this seems to work. Any comments are highly welcome though.

    What it does is:
    Check gear switch, raise or lower the gear accordingly by sending the code to Link2FS
    If 1 or more gears are in transit or have failed turn on the red led. If the gear is fully down turn on its green led.
    I had a lot of trouble getting the red led logic to work, but I think the code works good now. I even failed the gears in FSX to check

    Greetings,
    Eric

    Code:
    /*
    GearPanel module
    Version: 0.1
    latest change: 31-01-2012: 1st version


    General use:
    - Use a (On/Off) switch to raise or lower the gear.
    - Show gear status through leds.
    - Green ON = gear down and locked.
    - Red ON is gear unlocked (in transit or unsafe)
    - all leds off: gear is up

    Inputs:
    - Gear up/Down switch (Single Pole Single Throw) On/Off)
    - sends a signal D071(High) or D070 (LOW) to serialport. interface software captures this code
    and sends key command (Shift-G) or (Control G) to FSX.
    key commands are set through FSUIPC (registred version) or could be regular fsx keys.


    Outputs:
    - LED Green - Left gear down
    - LED Green - Right gear down
    - LED Green - Nose gear down
    - LED Red - Gears in Transit or one or more failed gears

    Pins:
    - 7 Gearswitch (On/Off)
    - 5 Right gear Green Led
    - 4 Nose gear Green Led
    - 3 Left gear Green Led
    - 12 Red Led transit or fail

    */

    //pinnumbers
    int SWgear = 7;
    int LEDleftgear = 3;
    int LEDnosegear = 4;
    int LEDrightgear = 5;
    int LEDunsafe = 12;

    //global variable declarations:
    bool geardown; //to check if gear is down
    bool geartransit[3]; //to check if all gear is fully down
    String gearright; // to hold the geardata [range 000 - 100]
    String gearleft;
    String gearnose;

    char xx; //needed to read the serial data

    void setup()
    {
    // configure pins
    pinMode(7, INPUT_PULLUP); // pin 7 is switch
    pinMode(5, OUTPUT); // green Right gear
    pinMode(4, OUTPUT); // green Nose gear
    pinMode(3, OUTPUT); // green Left Gear
    pinMode(12, OUTPUT); // Red unsafe

    //fill variables with data
    gearright = "100"; //100 = initial value not sure if needed, I dont like empty variables
    gearleft = "100";
    gearnose = "100";

    geartransit[0] = false;
    geartransit[1] = false;
    geartransit[2] = false;

    // TESTRUN leds on then off to check if they work, could also be done with pushbutton " test"

    digitalWrite(5, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(12, HIGH);
    delay(2000);
    digitalWrite(5, LOW);
    digitalWrite(4, LOW);
    digitalWrite(3, LOW);
    digitalWrite(12, LOW);
    // endtest leds

    if (digitalRead(SWgear) == LOW) // switch is off = gear up
    {geardown = false;}
    else {geardown = true;} // switch is on = gear down

    //
    Serial.begin(115200); // start serial connection
    }

    void loop()
    {
    if (Serial.available() > 0)
    {
    xx = getChar();
    if (xx == 'I') // check to see if nosegear data comes in
    {
    gearnose = ""; // Empty gearnose string
    gearnose += getChar(); //Read the first charactor sent
    gearnose += getChar(); //Read the second charactor sent and add it to the first
    gearnose += getChar(); //Read the third charactor sent and add it to the first

    // If nose gear is not up OR not down
    if (gearnose > "000" && gearnose < "100")
    {
    digitalWrite(LEDnosegear, LOW); // turn off the green led
    geartransit[0] = true; //set flag for red led this gear is in transit

    }
    // If nosegear is fully UP
    if (gearnose == "000")
    {
    digitalWrite(LEDnosegear, LOW); // turn off green led
    // if gearhandle was set to down, but gear stays up then flag red led
    if (geardown){geartransit[0] = true;} else {geartransit[0] = false;}
    }

    // If nosegear is fully DOWN
    if (gearnose == "100")
    {
    digitalWrite(LEDnosegear, HIGH); // turn ON green led
    // if gearhandle was set to UP, but gear stays down then flag red led
    if (geardown == false){geartransit[0] = true;} else {geartransit[0] = false;}
    }
    }
    // -----------------------------
    if (xx == 'J') // check to see if leftgear data comes in
    {
    gearleft = ""; // Empty gearnose string
    gearleft += getChar(); //Read the first charactor sent
    gearleft += getChar(); //Read the second charactor sent and add it to the first
    gearleft += getChar(); //Read the third charactor sent and add it to the first
    // If left gear is not up OR not down
    if (gearleft > "000" && gearleft < "100")
    {
    digitalWrite(LEDleftgear, LOW);
    geartransit[1] = true; //set flag for red led this gear is in transit
    }
    // If leftgear is fully UP
    if (gearleft == "000")
    {
    digitalWrite(LEDleftgear, LOW); // turn green led OFF
    // if gearhandle was set to down, but gear stays up then flag red led
    if (geardown){geartransit[1] = true;} else {geartransit[1] = false;}

    }
    // If leftgear is fully DOWN
    if (gearleft == "100")
    {
    digitalWrite(LEDleftgear, HIGH); // turn green led ON
    // if gearhandle was set to UP, but gear stays down then flag red led
    if (geardown == false){geartransit[1] = true;} else {geartransit[1] = false;}
    }


    }
    // -----------------------------
    if (xx == 'K') // check to see if rightgear data comes in
    {
    gearright = ""; // Empty gearnose string
    gearright += getChar(); //Read the first charactor sent
    gearright += getChar(); //Read the second charactor sent and add it to the first
    gearright += getChar(); //Read the third charactor sent and add it to the first

    // If left gear is not up OR not down
    if (gearright > "000" && gearright < "100")
    {
    digitalWrite(LEDrightgear, LOW); //turn green led OFF
    geartransit[2] = true; //set flag for red led this gear is in transit
    }

    // If rightgear is fully UP
    if (gearright == "000")
    {
    digitalWrite(LEDrightgear, LOW); // turn green led OFF
    // if gearhandle was set to down, but gear stays up then flag red led
    if (geardown){geartransit[2] = true;} else {geartransit[2] = false;}
    }

    // If rightgear fully down
    if (gearright == "100")
    {
    digitalWrite(LEDrightgear, HIGH); //turn green led ON
    // if gearhandle was set to UP, but gear stays down then flag red led
    if (geardown == false){geartransit[2] = true;} else {geartransit[2] = false;}
    }
    }
    // -----------------------------

    // End of If then checks for gears
    } // endif serial available

    GearCheck(SWgear); // check gear switch status on pin 7
    // --> see void. could be done here too without a call to a seperate void


    // Check to turn RED led On or Off
    // Only if all gears report fully up or fully down set red led off, else set red led on
    if (geartransit[0] == false && geartransit[1] == false && geartransit[2] == false)
    {digitalWrite(LEDunsafe, LOW);} // all are safe, turn led OFF
    else // one or more are in transit or failed
    {digitalWrite(LEDunsafe, HIGH);} // set red led ON


    }// end void loop

    // routine copy/pasted from Mycockpit.org for other way of reading serial data.
    char getChar()
    {
    while(Serial.available() == 0); // wait for data
    return((char)Serial.read());
    }

    void GearCheck(int gearpin)
    {
    if (digitalRead(gearpin) == LOW) // switch is set to OFF
    {
    // check to see if its needed to send switchdata to the serial
    if (geardown == true) // it was on, now off, send keys to serial
    {
    geardown = false;
    Serial.print("D070"); // = set gear up
    delay(11);
    }
    }
    if (digitalRead(gearpin) == HIGH) // switch is on
    {
    // check to see if its needed to send switchdata to the serial
    if (geardown == false) // it was off, now on, send keys to serial
    {
    geardown = true;
    Serial.print("D071"); // = set gear down
    delay(11);
    }
    }
    }
    Last edited by Sammy-E; 02-01-2013 at 09:19 PM. Reason: removed pin 11 from code, changed thread titel

  2. #2
    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: gearpanel with code

    Eric ,, This thread along with the other one will be deleted shortly as they don't comply with what we are on about in here.

    I take it you have read this ,,,
    http://www.mycockpit.org/forums/ardu...ease-read.html

    Maybe you should post your info in the teensy forums.

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

  3. #3
    25+ Posting Member



    Join Date
    Aug 2009
    Location
    Oss - Netherlands
    Posts
    61
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    re: gearpanel with code

    Hey Jim,
    sorry if I misunderstood this forum. I have read the rules, but I am a little confused. My posts are all about Link2Fs and arduino. I honestly thought that a Teensy is an Arduino board. In fact, I have learned all my coding from within this forum, without any conversions. But, I if you feel these posts are not meant for this Forum I will not complain and follow the rules. No worries!
    greettings,
    Eric

  4. #4
    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: gearpanel with code

    OK Eric ,, you were confused ,,, The Teensy and some other brands of "compatible" cards are not fully "Arduino compatible" and most of them are marketed without fully defining the differences. To put it simply ,, I can make some Arduino code that wont work on your Teensy and you can make some Teensy "Arduino" code that wont work on my Arduino.

    Without getting too technical about this ,, some simple differences are in the pins and what they do ,, for instance the built in LED is on pin 13 on Arduino's and its on pin 6 or 11 in the Teensy ... that may not appear a big deal but it matters a lot when you want to set what the pin is going to be used for.
    Others are ,, Pins 0 and 1 are used in the USB serial coms on the Arduino ,,, so we can't use them but you can ,,, another is the pins for PWM are different between the two cards.

    All this drifts towards a total mess up if there are PDE / INO's floating around in this forum that are not 100% Arduino pure code.

    To an experienced user ,, the differences are just "part of the fun" of using these cards but to a novice just taking the first steps into our cockpit building fun ,,, it's a confusing nightmare.

    I diverse here with a bit of history ,, it seems like years ago I tried an Arduino card as a controller in my 3rd motion platform ,,, it was brilliant ,, then I thought ,, why the heck aren't we using them in general cockpit building ??? so I started this sub-forum to "spead the word".
    My specific target was (is) the absolute "newbie" and it will remain so.

    I want the "newbies" first play with these things to be as easy and straight forward as possible ,,, so hence "pushing" other breeds of cards or posting non compatible code is a "no - no".

    There are also some extremely talented guys in this forum (away ahead of me) with some complex projects on the make ,,, so the forums not all about "newbies" ,, but if different cards / coding were posted here then it could just be too big a hurdle for some-one-else to give a complex project a try.

    On the more "higher end" ,, I deal with a lot of e'mails and I am aware of Universitys and Training set-ups that are using code plucked straight from this forum so a big THANK YOU to the Guys that posted code ,,, and ,, there are a lot of "watchers" that never post.

    If your happy to ensure your code is 100% Arduino pure code and not "advertise" other makes of cards ,, then great stuff ,,, fire ahead and have fun ,, welcome to our wee world.

    I had a quick look-see at your code and it appears to comply with true Arduino code but I never tried it.
    In the other thread you started can you edit out all the "advertising" for that card and if you can't alter the thread heading ,, I can do that for you.

    Cheers ,,, Jim
    P.S. Sorry to be so long winded but I though I better spell it all out.
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  5. #5
    25+ Posting Member



    Join Date
    Aug 2009
    Location
    Oss - Netherlands
    Posts
    61
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    re: gearpanel with code

    Hi Jim,
    I understand it and it makes a lot of sense. may I suggest you add this to the forum rules, as it might help others too? Arduino's are not always arduinos and I didn't get that. I do now.

    I have tried to edit my posts as requested, but can't change the thread title, only the text.
    If you would like to do that or delete them its oke.

    Greetings,
    Eric

  6. #6
    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: gearpanel with code

    All done ,,, Thanks Eric ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

Tags for this Thread