Results 1 to 4 of 4
  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

    Having issues with some code...

    Hi all,
    Well I thought I would try out the servo's seeing there was a tutorial on youtube, but for some reason the code won't compile,
    Code:
    /* 
        This code is in the public domain
        For use with "Link2fs_Multi"
        Jimspage.co.nz
        My thanks to the Guys that gave me snippets of code. 
        
        Here is the basic concept of my lay-outs.
        You could actually use this INO as a starting point for your own project.
        Deleting all the comments makes it really simple to follow once you understand the concept
    */
    
    
    #include 
    VarSpeedServo myServo;
    
    
    
    
    int CodeIn;// The normal declearations go here
    int KpinNo; 
    int Koutpin;
    String tc;
    int tcl;
    int val;
    
    
    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
    
    
    void setup(){
    {
    myservo.attach(9);
    Serial.begin(115200); 
           // The normal startup stuff goes here
    }
    
    
    void loop() {
      {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
      if (Serial.available()) {  //Check if anything there
        CodeIn = getChar();      //Get a serial read if there is.
        if (CodeIn == '=') {EQUALS();} // The first identifier is "=" ,, goto void EQUALS
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<" ,, goto void LESSTHAN
        if (CodeIn == '?') {QUESTION();}// The first identifier is "?" ,, goto void QUESTION
        if (CodeIn == '/') {SLASH();}// The first identifier is "/"  ,, goto void SLASH (Annunciators)
      }
    }
    
    
    char getChar()// Get a character from the serial buffer(Dont touch)
    {
      while(Serial.available() == 0);// wait for data (Dont touch)
      return((char)Serial.read());// (Dont touch) Thanks Doug
    }
    
    
    void OTHER(){
    /* In here you would put code that uses other data that
    cant be put into an "extraction void" that references something else.
    Also in here you would put code to do something that was not
    relying on a current extraction.
    (Remember - The identifier voids only trigger when it receives that identifier)
    */
    }
    
    
    void EQUALS(){      // The first identifier was "="
           CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'w'://Found the second identifier
           //Do something
           tc = "";
          tc += getChar();
          tc += getChar();
          tc += getChar();
          int tcl = tc.toInt();
          
          val = tcl;
          val = map(val, -127, +127, 0, 154)
          myservo.slowmove(val,45);
          serial.printIn
        break;
         
        
         }
    }
    
    
    void LESSTHAN(){    // The first identifier was "<"
          //Do something (See void EQUALS)
    }
    
    
    void QUESTION(){    // The first identifier was "?"
           //Do something (See void EQUALS)
    }
    
    
    void SLASH(){    // The first identifier was "/" (Annunciators)
      //Do something (See void EQUALS)
    }
    the error is:
    Hsi_Cdi.ino: In function 'void setup()':
    Hsi_Cdi:30: error: 'myservo' was not declared in this scope
    Hsi_Cdi:35: error: a function-definition is not allowed here before '{' token
    Hsi_Cdi:92: error: expected `}' at end of input



    Hope you all can shed some light on this, thanks
    Henri

  2. #2
    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: Having issues with some code...

    Hi Henri,
    1)
    missing something rigth after #include
    I think it would be : #include "VarSpeedServo.h"
    Of course, I hope you have correctly install your varspeedservo Library in the arduino IDE
    C:\Users\_YOUR_LOGIN_\Documents\Arduino\libraries
    replace _YOUR_LOGIN_ with your windows login
    2)
    At the begining of your code, you have globaly declared myServo
    in the setup fonction, you use myservo. Warning it's case sensitive
    3)
    always in the setup fonction
    remove one "{"
    so after 2) and 3)

    void setup()
    {
    myServo.attach(9);
    Serial.begin(115200);
    // The normal startup stuff goes here
    }

    4)
    Same error as 2) in the Equals fonction
    myServo.slowmove(val,45);
    5)
    always in the equals fonction
    You've forgotten a ";" right after this line
    val = map(val, -127, +127, 0, 154)
    so
    val = map(val, -127, +127, 0, 154);
    It's a Language C syntax
    6)
    In the same equals fontion
    serial.printIn
    As far I know, "printIn" isn't a member of serial or Serial (case sensitive)
    Remove this line of code or put this one
    Serial.println(val);
    for debugging in the serial console

    I think it's all, I have not tested the sketch so I just look for errors

    Ryan

  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: Having issues with some code...

    Hi Ryan,
    Thanks for the corrections, got it working using one of Jim's example sketches but will use this for further reference.
    Although now I have run into yet another problem... the servo is extremely jittery, I have got no Idea where to go from here!
    Hope you can point me in the right direction once again!
    Henri

  4. #4
    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: Having issues with some code...

    Hi Henri
    Jim's examples and examples on arduino web site are always a good source of inspiration
    I've never used servo on arduino, but I think the values you send to the servo fluctuate too rapidly or are not stable. you can debug with Serial.println(your_variable_value); into the serial console
    Depending of the precision of the variable value. Are you reading this value from a potentiometer ?
    you can test by sending one fixed value at a time with a simple test sketch
    sometimes jitters are produced by a bad electrical connections between arduino and servo or bad solder inside the servo (it already happened to me on a RC model)
    Hope this can help you
    Ryan