Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Aviation Enthusiast
    Join Date
    Sep 2013
    Location
    Cornwall, UK
    Posts
    42
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Turning switches off

    When I turn off a switch using the simconnect codes will it automatically turn off the switch in the VC? i.e. if I had a toggle switch set to send the code for landing lights on when I turn it off will it turn the landing lights off or would I need to add code to send a separate command?

  2. #2
    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: Turning switches off

    You'll need to send a command for the OFF state of the switch.

  3. #3
    Aviation Enthusiast
    Join Date
    Sep 2013
    Location
    Cornwall, UK
    Posts
    42
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Turning switches off

    How do I detect when it is off?

  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: Turning switches off

    I use I/O pin 13 as an output for quick diagnostics since it has the on-board LED indicator.

    Summary:
    1.) PinMode13 as an output
    2.) PinMode another as your input
    3.) digitalRead(InputPin)
    4.) if (InputPin == HIGH) then digitalWrite(Output13 , HIGH) else digitalWrite(Output13 , LOW)
    5.) After confirming proper operation, replace digitalWrite command with the serialPrint commands


    The above is a generic process since I'm unsure of your skill level.

    If you have further questions, please post your code so that we can walk through it together with a clear and concise direction.

    JM

  5. #5
    Aviation Enthusiast
    Join Date
    Sep 2013
    Location
    Cornwall, UK
    Posts
    42
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Turning switches off

    I'm pretty new to Arduino but that was very helpful. So this would be placed in the main loop, am I correct?

  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: Turning switches off

    Yes. Place it the main loop. Also, you'll want to create a string called InputPinold, or something similar, and use it as such:

    if (InputPin != InputPinold){
    if (InputPin == HIGH) then digitalWrite(Output13 , HIGH) else digitalWrite(Output13 , LOW)
    InputPinold = InputPin
    }

    The above will prevent the execution of the digitalWrite command at every pass of the loop when it reads the state of the input pin. Without it and using a command to toggle the gear up or down, the arduino will send a command for the gear- even though the switch did not physically change states. This would cause the gear to up on the first pass, down on the second, up on the third, etc.

  7. #7
    Aviation Enthusiast
    Join Date
    Sep 2013
    Location
    Cornwall, UK
    Posts
    42
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Turning switches off

    So I tried this an I had it working with the LED. However I changed it to serial print C01 and C02 for the gear and it filled my serial viewer with C01 - any help?
    int val = 0;int inputPin = 2;
    int valOld = 0;


    void setup()
    {
    pinMode(inputPin, INPUT);
    Serial.begin(9600);
    digitalWrite(inputPin, HIGH);
    }


    void loop() {
    val = digitalRead(inputPin);
    if (val != valOld); {
    if (inputPin == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };
    val == valOld;
    }
    }


  8. #8
    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: Turning switches off

    inputPin always will equal 2.
    ReWrite - if (val == HIGH)
    if (
    val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };

  9. #9
    Aviation Enthusiast
    Join Date
    Sep 2013
    Location
    Cornwall, UK
    Posts
    42
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Turning switches off

    You are brilliant! Thank you.

    Just one more question: The above code (with the fix that you suggested) is sending the line 'C02'/'C01' repeatedly whereas I thought the assignment of varOld would stop this from happening? Have I done something wrong?

  10. #10
    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: Turning switches off

    Sorry. My mistake from post #6.

    edited post #6 to read:
    InputPinold = InputPin

    JM

Page 1 of 2 12 LastLast