Results 1 to 3 of 3
  1. #1
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Jul 2016
    Location
    United Kingdom
    Posts
    6
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    difficlty making a vsi indicator (code)

    hey, i have built an indicator that uses a servo and a gear ratio to move the needle. here is my attempted code that i have tried for many hours and cant get it to work. any suggestions?

    #include
    Servo vsiServo;






    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;
    String vsi;


    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;


    void setup()
    {
    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    for (int KoutPin = 2; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    pinMode(9, OUTPUT);// For the servo.
    vsiServo.attach(9);

    }


    void loop() {
    {KEYS();} //Check the "keys" section
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();} // The first identifier is "="
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
    }


    }


    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }


    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }


    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'L'://Found the second identifier ("G" Flaps position)
    vsi = "";
    vsi += getChar();
    vsi += getChar();
    vsi += getChar();
    int vsiint = vsi.toInt();
    vsiint = vsiint * 0.03; // getting a big number down to servo degrees
    vsiint = (vsiint + 90); //making it so 0 on the isntrument is = to 90 degrees
    if((vsiint) > 90 && vsiint < 151) // chacking if its positive (for now until i get it working ill attempt negatives)
    vsiServo.write(vsiint); //wirting it
    break;
    }
    }


    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;
    }
    }
    void SLASH(){ // The first identifier was "/" (Annunciator)
    //Do something
    }
    void KEYS()
    {
    Kstringnewstate = "";
    for (int KpinNo = 2; KpinNo < 70; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 2));
    if (KpinStateSTR != KoldpinStateSTR)
    {
    if (KpinNo != 13){
    //Serial.print ("D");
    //if (KpinNo < 10) Serial.print ("0");
    // Serial.print (KpinNo);
    // Serial.println (KpinStateSTR);
    }
    }
    Kstringnewstate += KpinStateSTR;
    }
    Kstringoldstate = Kstringnewstate;
    }

  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: difficlty making a vsi indicator (code)

    Long time since I was on the forum, but I will give it a try.
    If I remember correctly you have to change this lines.

    for (int KoutPin = 2; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"

    and:

    for (int KpinNo = 2; KpinNo < 70; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));

    The pins 2 to 69 ar decleared as inputs for buttons and at the same time you decleare pin 9 (the servo) as output.
    Try to change the lines and separate pins for input and output.
    ie:
    for (int KoutPin = 20; KoutPin < 70; KoutPin++)

    I've had my simulator packed for a couple of years now, so I may not remember correctly. But give it a try.


    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Jul 2016
    Location
    United Kingdom
    Posts
    6
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: difficlty making a vsi indicator (code)

    Quote Originally Posted by BuzziBi View Post
    Long time since I was on the forum, but I will give it a try.
    If I remember correctly you have to change this lines.

    for (int KoutPin = 2; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"

    and:

    for (int KpinNo = 2; KpinNo < 70; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));

    The pins 2 to 69 ar decleared as inputs for buttons and at the same time you decleare pin 9 (the servo) as output.
    Try to change the lines and separate pins for input and output.
    ie:
    for (int KoutPin = 20; KoutPin < 70; KoutPin++)

    I've had my simulator packed for a couple of years now, so I may not remember correctly. But give it a try.


    thanks i got it fixed a few weeks ago i appreciate your reply