Jump to content

AMirrodin

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by AMirrodin

  1. i'm sorry, I don't actually understand what you mean.

    Firstly, you saying to get that working (at-least, at the moment) I need to compile from source with that code?

    And not sure what you mean by the analogue 0/1 thing...

    Yes you do need to compile from source with the given code. As for the analogue 0/1, I was trying to say the voltage usually not going to stay the same going across the analogue component. So the values may change by + or - one every time the arduino reads, even if the component does not change positions. Say your initial read is 10, the next read could be 11, 9, or 10. The reads should balance on one value.

    I hope I am not adding more confusion... If I am, then ignore me trying to explain it because I am not an expert

  2. I am still amazed at how this plugin is turning out to make me do a hardware project similar to what Mulbin is doing.

    As for what Pantner said:

    Would also like an analogue throttle, do you think that is possible?

    I did find a way for an analog value to be sent to control the throttle with an older version of this plugin. I am posting the code. Just be aware that it is for the .11 version since I forgot to update until yesterday. I did notice the since it is analog there is no way to make a value be constantly the same, other than 0 or 1, due to the nature of analog components being electrically noisy.

    Arduino code


    //Code here is in the KSPIODemo file
    case 1:
    FuelLights();
    SendThrottle();//NEW LINE
    break;
    }

    // I put this function in the Utilities file
    void SendThrottle(){
    CurThrottle = analogRead(ThrPIN);
    CurThrottle = 1023.0 - CurThrottle;
    CurThrottle = map(CurThrottle,657.0,1023.0,0.0,100.0)/100.0;
    if(PrevThrottle != CurThrottle){
    char ThrottleChar[4];
    dtostrf(CurThrottle,4,2,ThrottleChar);
    String ThrottleStr = String(ThrottleChar);
    Serial.println("KSP;1;"+ThrottleStr);
    }
    PrevThrottle = CurThrottle;
    }

    Plugin Code


    if (parsed[0] == "KSP")
    {
    short messageID = (short)double.Parse(parsed[1]);
    if (messageID == 0)
    {
    DisplayFound = true;
    }
    //NEW CODE BELOW
    if (messageID == 1)
    {
    float ThrVal = float.Parse(parsed[2]);
    FlightInputHandler.state.mainThrottle = ThrVal;
    }
    }

  3. Found a way to send commands from my arduino to the plugin. I made a new function to check if a button was pressed and if it was then it executed Serial.println(F("KSP;1")). I also had to put a new if statement in the plugin C# code to look for the message.

    Arduino code snip:


    void SendStage(){
    if(digitalRead(2) == HIGH){
    Serial.println(F("KSP;1"));
    }
    }

    Plugin code snip:


    //This part is usually here
    if (parsed[0] == "KSP")
    {
    short messageID = (short)double.Parse(parsed[1]);
    if (messageID == 0)
    {
    DisplayFound = true;
    }
    //Added code below
    if (messageID == 1)
    {
    Staging.ActivateNextStage();
    }
    }

  4. Mine is an R3

    The sample code works for me on my R3 mega, although I did notice that I have to launch my rockets from the VAB and not straight from the launch pad or my communication light wouldn't turn on... Might be something I/you/Zitronen/we should look into

    If you are wondering about the communication light, I just added a new variable definition to the code and changed the handshake LED to my new one.

×
×
  • Create New...