Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: help with code

  1. #1
    10+ Posting Member
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    11
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    help with code

    why does the arduino compiler tell me this error

    pitch_code.ino: in function ' void LESSTHAN():
    pitch_code:83: error: jump to case label
    pitch_code:73: error: crosses initiatializaton of int pitchsi

    how do I fix it
    Attached Files Attached Files

  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: help with code

    Hello pieterpret,
    I've successfully compiled your code simply adding { and } in your case statement

    case 'Q':
    {
    pitch = "";
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    int pitchsi = pitch.toInt();
    pitchsi = (pitchsi + 30);
    pitchservo.write(pitchsi);
    break;
    }

    case 'R':
    {
    roll += "";
    roll += getChar();
    roll += getChar();
    roll += getChar();
    roll += getChar();
    roll += getChar();
    int rollsi = roll.toInt();
    rollsi = (rollsi + 30);
    rollservo.write(rollsi);
    break;
    }

    default:
    break;

    I think arduino compiler is not as compliant as it should to the C language
    Ryan

  3. #3
    10+ Posting Member
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    11
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: help with code

    thanks, sometimes get I so irritated with something that I am not able to clear my thoughts and think straight

  4. #4
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Mar 2014
    Location
    TURKEY
    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: help with code

    Hello
    I use these cod , pitch is working but roll is not working.
    Have you any idea.
    Regards

  5. #5
    10+ Posting Member
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    11
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: help with code

    can you and your source file or code to you post, it would really help to figure out whats wrong

  6. #6
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Mar 2014
    Location
    TURKEY
    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: help with code

    Thank you pieterpret,
    my cod as follow

    #include


    Servo pitchservo;
    Servo rollservo;


    int CodeIn;
    String pitch;
    String roll;
    void setup(){
    pitchservo.attach(10);
    rollservo.attach(;
    Serial.begin(115200);


    }


    void loop() {
    {
    OTHER();
    }
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {
    EQUALS();
    }
    if (CodeIn == '<') {
    LESSTHAN();
    }
    if (CodeIn == '?') {
    QUESTION();
    }
    if (CodeIn == '/') {
    SLASH();
    }
    }
    }


    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());// (Dont touch) Thanks Doug
    }


    void OTHER(){

    }


    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {
    case 'A':


    break;


    case 'W':

    break;


    case 'a':

    break;
    }
    }


    void LESSTHAN(){


    CodeIn = getChar();
    switch(CodeIn) {
    case 'A':
    break;


    case 'Q':
    {
    pitch = "";
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    int pitchsi = pitch.toInt();
    pitchsi = (pitchsi + 30);
    pitchservo.write(pitchsi);
    break;
    }


    case 'R':
    {
    roll += "";
    roll += getChar();
    roll += getChar();
    roll += getChar();
    roll += getChar();
    roll += getChar();
    int rollsi = roll.toInt();
    rollsi = (rollsi + 30);
    rollservo.write(rollsi);
    break;
    }




    }
    }


    void QUESTION(){ // The first identifier was "?"
    //Do something (See void EQUALS)
    }


    void SLASH(){ // The first identifier was "/" (Annunciators)
    //Do something (See void EQUALS)

    What is wrong?

  7. #7
    10+ Posting Member
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    11
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: help with code

    try my code.it work better i don't see any reason for your code not to work but i think it may be on the wiring side on in the way that you set it up. I've used this code a few time with now problems

    #include
    Servo pitchServo;
    Servo rollServo;




    #define rollServ 11
    #define pitchServ 10




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


    String pitch;
    String roll;




    void setup(){


    pitchServo.attach(pitchServ);
    rollServo.attach(rollServ);
    Serial.begin(115200);
    pinMode(pitchServ, OUTPUT);// For the servo.
    pinMode(rollServ,OUTPUT);




    }


    void loop() {
    {
    OTHER();
    }
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {
    EQUALS();
    }
    if (CodeIn == '<') {
    LESSTHAN();
    }
    if (CodeIn == '?') {
    QUESTION();
    }
    if (CodeIn == '/') {
    SLASH();
    }
    }
    }


    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());// (Dont touch) Thanks Doug
    }


    void OTHER(){


    }


    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {
    case 'A':


    break;


    case 'W':


    break;


    case 'a':


    break;
    }
    }


    void LESSTHAN(){


    CodeIn = getChar();
    switch(CodeIn) {
    case 'A':
    break;


    case 'R'://Found the second identifier ("R" roll position)
    {
    roll = "";
    roll +=getChar();
    roll +=getChar();
    roll +=getChar();
    roll +=getChar();
    roll +=getChar();
    roll +=getChar();
    int rolli = roll.toInt();
    rolli = (rolli +90);
    //rolli = map(rolli, 0, 180, 0, 45);
    rollServo.write(rolli);
    }
    break;


    case 'Q'://Found the second identifier ("Q" pitch position)
    {
    pitch = "";
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    pitch += getChar();
    int pitchi = pitch.toInt();
    pitchi = (pitchi*2 +90);// Centres servo.
    pitchServo.write(pitchi); // send it out


    }
    break;


    }
    }


    void QUESTION(){ // The first identifier was "?"
    //Do something (See void EQUALS)
    }


    void SLASH(){ // The first identifier was "/" (Annunciators)
    //Do something (See void EQUALS)
    }

  8. #8
    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: help with code

    I found youre error

    The:

    case 'R':
    {
    roll += "";

    should be:

    case 'R':
    {
    roll = "";

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

  9. #9
    10+ Posting Member
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    11
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: help with code

    such a small mistake can cause an unwanted headache

  10. #10
    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: help with code

    Now, now ...
    One thing I've learned since I started........all errors are fatal (and wery hard to find)
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

Page 1 of 2 12 LastLast