Results 1 to 7 of 7
  1. #1
    75+ Posting Member
    Join Date
    Mar 2013
    Location
    Adelaide, South Australia
    Posts
    136
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Potentiometer Help

    Hi ,
    Having some issues with the coding
    trying to use a potentiometer for the obs knob and translating that via mapping it, yet I cant seem to get it to work,

    just the last part of the code
    Code:
    void INPUTS() // Simconnect codes and "Keys" section
    {
      Kstringnewstate = "";
      for (int KpinNo = 8; KpinNo < 70; KpinNo++){ 
        KpinStateSTR = String(digitalRead(KpinNo)); 
        KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 8));
        if (KpinStateSTR != KoldpinStateSTR)
        {
          if (KpinNo != 13){ 
            if (KpinNo == 8 && KpinStateSTR == "0"){Serial.println ("C01");} //sets gear handle up
            if (KpinNo == 9 && KpinStateSTR == "0"){Serial.println ("C02");} //sets gear handle down
            if (KpinNo == 10 && KpinStateSTR == "0"){Serial.println ("C15");} //Decrements flap handle position
            if (KpinNo == 11 && KpinStateSTR == "0"){Serial.println ("C14");} //Increments flap handle position
            if (KpinNo == 12 && KpinStateSTR == "0"){Serial.println ("A02");} //Increments COM1sb by one MHz
            if (KpinNo == 14 && KpinStateSTR == "0"){Serial.println ("A01");} //Decrements COM1sb by one MHz
            if (KpinNo == 15 && KpinStateSTR == "0"){Serial.println ("A426543");} //Sets transponder code to 6543
            val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
      val = map(val, 0, 1023, 0, 360);     // scale it to use it with the servo (value between 0 and 180)   
      {Serial.println ("A33") (val);
      }
      
            //  Add more here but remember to change the figure in the next line down. (the 15)
            if (KpinNo > 15){ //Change pinNo number to same as the highest one used for simconnect codes.(the 15)
            Serial.print ("D"); 
          if (KpinNo < 10) Serial.print ("0");
          Serial.print (KpinNo);
          Serial.println (KpinStateSTR);
            }
          }
        }      
        Kstringnewstate += KpinStateSTR;
      }
      Kstringoldstate = Kstringnewstate;
    }// end of INPUTS void
    any help would be appreciated

    Thanks

    Henri

  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: Potentiometer Help

    I suggest you study some codes for servos. Think about the difference of 180 degrees servos and the instrument that has 360 degree rotation of the needle, and position determination of the servo.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    75+ Posting Member
    Join Date
    Mar 2013
    Location
    Adelaide, South Australia
    Posts
    136
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Potentiometer Help

    Um, I mean using a raw potentiometer as an input for the obs knob.

    Thanks
    Henri

  4. #4
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Potentiometer Help

    I recommend using a Rotary Encoder to make your OBS or HDG knob.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  5. Likes Mikeb1028 liked this post
  6. #5
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Potentiometer Help

    Henri, in response to your last thread Jim suggested that you should learn some basic C programming before trying to write your own sketches. You’ve got the same problem here; you are confusing string variables with integer variables and using them interchangeably. Can’t do that, it doesn’t work (as you have found out).


    C programming is really not hard to learn, there are plenty of books and on-line tutorials to get you started. You will gain a tremendous feeling of accomplishment when you can read a line of code and understand exactly what it does and why it’s there, and eliminate your current frustration from just copying code and not having it work.
    ---Steve


  7. Likes Mikeb1028 liked this post
  8. #6
    75+ Posting Member
    Join Date
    Mar 2013
    Location
    Finland
    Posts
    106
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Potentiometer Help

    Normally potentiometers read analogread (value) and if else what doing.
    but flight sim have better use encoder if need use knob.
    jims site have good examples and help to encoder and many other. just i learn thats too
    and can google net many examples how use.
    And servo have many way too how tell to servo were must go position.

  9. #7
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Potentiometer Help

    Hi Henri,
    I suggest you to use rotary encoder as others in this forum
    But even with potentiometer, it'll work very well
    Many things I don't understand in your code
    1) you want to move the obs knob so you use "A33" code but obs code is normally "B33"
    2)your print code:
    Serial.println ("A33") (val);
    May be I wrong, but I not sure the print C language command in arduino accepts 2 parameters. Second point, the variable val need to be convert in ascii characters because it's an integer value

    I'll do that...(a code among many other)

    char buf[6]; <- temporay variable for conversion. Need to be stated in your global variable section or in the localy fonction INPUT()

    val=map(analogRead(potpin),0,1023,1,360);
    Serial.print("B33");
    Serial.println(itoa(val,buf,10));

    Hope this help you a little

    Ryan