-3

I'm a first year persuing Mechatronic engineering, and I'm having trouble with this code that I am using to control a biped robot for my project.

#include <servo.h>
Servo myservoa;
           myservob;
           myservoc;
           myservod;
int     myservoa=10;
          myservob=55;
          myservoc=25;
          myservod=125;

void setup() {
    myservoa.attach(2)
    myservob.attach(3)
    myservoc.attach(4)
    myservod.attach(5)
}

void loop() {
    for pos=10;pos<=75;pos+=1;
    {
        myservoa.write(pos);
        delay(1000);
    }
    for pos=55;pos<=100;pos+=1;
    {
        myservob.write(pos)
        delay (1800)
    }
    for pos=25;pos<=165;pos+=1;
    {
        myservoc.write(pos)
        delay (1000)
    }
    for pos=125;pos<=170;pos+=1;
    {
        myservod.write(pos)
        delay (1800)
    }
}

Could there be an error in the code?

7
  • 5
    Yeah, some syntax errors. For now I formatted your code correctly and changed the Void and Int to lower case. But you really have to describe, what your actual problem is. You should get error messages during compilation. It is mandatory to add those to your question (click at "edit" under your question do directly editing it)
    – chrisl
    Jun 30, 2018 at 16:02
  • 4
    @chrisl ... "some" syntax errors...? I think it's easier to list the bits that aren't a syntax error.
    – Majenko
    Jun 30, 2018 at 16:44
  • 4
    @user47756 You really need to go back to basics with your C++ syntax knowledge. Learn the basic syntax before you try writing code.
    – Majenko
    Jun 30, 2018 at 16:45
  • Chrisl,what syntax errors did you get?
    – Jose Nick
    Jun 30, 2018 at 18:40
  • 2
    I think in total there are maybe 5 lines there that don't have syntax errors (not counting brackets)...
    – Majenko
    Jun 30, 2018 at 22:47

1 Answer 1

3

Could there be an error in the code?

You could say that, yes. Let's list all the syntax errors to start with:

#include <servo.h>
Servo myservoa;
           myservob; // This has no type. It's just a word by itself.
           myservoc; // This has no type. It's just a word by itself.
           myservod; // This has no type. It's just a word by itself.


int     myservoa=10; // You already defined myservoa as a Servo type.
          myservob=55; // This has no type. It's just a word by itself.
          myservoc=25; // This has no type. It's just a word by itself.
          myservod=125; // This has no type. It's just a word by itself.

void setup()
{
    myservoa.attach(2) // Semicolons must terminate all statements.
    myservob.attach(3) // Semicolons must terminate all statements.
    myservoc.attach(4) // Semicolons must terminate all statements.
    myservod.attach(5) // Semicolons must terminate all statements.
}

void loop()
{
    for pos=10;pos<=75;pos+=1; // Braces are missing, pos is not defined, and extra ;
    {
        myservoa.write(pos);
        delay(1000);
    }
    for pos=55;pos<=100;pos+=1; // Braces are missing, pos is not defined, and extra ;
    {
        myservob.write(pos)  // Semicolons must terminate all statements.
        delay (1800) // Semicolons must terminate all statements.
    }
    for pos=25;pos<=165;pos+=1; // Braces are missing, pos is not defined, and extra ;
    {
        myservoc.write(pos) // Semicolons must terminate all statements.
        delay (1000) // Semicolons must terminate all statements.
    }
    for pos=125;pos<=170;pos+=1; // Braces are missing, pos is not defined, and extra ;
    {
        myservod.write(pos) // Semicolons must terminate all statements.
        delay (1800) // Semicolons must terminate all statements.
    }
}

You really need to get to grips with the syntax of a language before you start programming in that language. I count just 6 lines (not including { and }) of valid C code there, and two of them are handed to you by the IDE.

3
  • I just pasted the code from a friend only that she used two servos. Majenko,could you kindly format my code and send it to me afresh?May be am getting trouble with many servos.
    – Jose Nick
    Jul 1, 2018 at 7:17
  • @user47756 This is no free coding service. Majenko pointed out the syntax errors in your code. Look at a basic C/C++ tutorial, learn and then rewrite the code yourself. You should not just copy from other people, because if you don't really understand the code, you will not be able to change it correctly to reach your goal. Show a bit effort here.
    – chrisl
    Jul 1, 2018 at 7:38
  • Ohh!I got it.My code is now OK and its running successfully upon uploading.Thanks guys.@majenko,@chrisl
    – Jose Nick
    Jul 1, 2018 at 14:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.