Results 1 to 3 of 3
  1. #1
    10+ Posting Member
    Join Date
    Feb 2011
    Location
    Williamson, GA, USA
    Posts
    23
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Starter2 PDE flap code

    I am really struggling with this code thingy. I look at it many times, wake up at night with serial this and that on my mind, just can't put it together. Below is a section from Jim's starter 2 that I need a little explanation to help me understand.
    flaps = "";
    flaps += char(Serial.read()); //Read the first charactor sent
    flaps += char(Serial.read()); //Read the second charactor sent and add it to the first
    flaps += char(Serial.read()); //Read the third charactor sent and add it to the other two.)
    if (flaps != flapsold){ // checks to see if its different to the "old" reading from the last loop
    if (flaps == "000") {digitalWrite(6, LOW);} //if its "000" then turn OFF the LED
    if (flaps > "000") { // if its greater than "000" then ,,,
    digitalWrite(6, HIGH); // set the LED on
    delay(50); // wait for 50 milliseconds
    digitalWrite(6, LOW); // set the LED off
    delay(50); // wait for 50 millisecon
    } // end of "moving" sequence. When there is no new change, the LED will go out.
    if (flaps > "030") {digitalWrite(7, HIGH);} else {digitalWrite(7, LOW);} //if flaps over "030" degree's then turn ON the LED

    flapsold = flaps; // Makes the old reading the same as the new reading.(So on the next reading it can check to see if it's different)

    What I would like to know more about is the red 000. Is this raw data or what? I built my flap device BA (before Arduino) using a radial switch and a series of resistors to give me a different reading on each detent intending it to be used with analog. I check Arduino's examples and they are way different than this code set up, so I assume this code does not work with my switch device. please comment. Thanks.
    We were meant to fly, even with a computer.

  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: Starter2 PDE flap code

    The red "000" is the flaps position in a string format. In reality it being in a string format is a bit of a "cheat" as it would be better code expressed as an integer or some other data form.

    Using a string to split off different readings is not good coding but I done it that way so it was easy for a novice to get started with the minimum of code in the older IDE's.. You can of course change the string into an integer and then manipulate it.

    Your actual switch arrangement is set up to be an analogue input with different positions being split off in the Arduino for different flap positions. (Quite a normal set-up) ,, But ,,, unless you have made your own program to interface with FSX (or FS9) then it would be a "hit and miss" method using Link2fs_inout as it only inputs keystrokes into flightsim. (of course you would have to change one of the pins to be an analogue input.etc )

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

  3. #3
    10+ Posting Member
    Join Date
    Feb 2011
    Location
    Williamson, GA, USA
    Posts
    23
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Starter2 PDE flap code

    OK, I have no idea what I'm doing except now I see there is a difference between the two and that there is more than one way to skin a dead cat...or write code. I'll study a little more in this area and make something happen. Thanks for the reply and enlightenment.
    We were meant to fly, even with a computer.