Let's Make Robots!

My first hand written code.

I have just written my first code in Arduino IDE. The code should make a servo move to 180 degrees wait one second and then move back to 0 degrees and repeat.

Here it is :

 

#include <Servo.h>

 

Servo servo1;

int posR = 179;

int posL = 0;

 

void setup()

{

  servo1.attach(9);

}

 

void loop()

{  

  { 

     servo1.write(posR);

     delay(1000);

  }

  {

    servo1.write(posL);

    delay(1000);

  }  

}

My question is, do you think my code will do what it's suppose to do I have to change something?

Any help is well appreciated!

 

 

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The main loop is the thing labeled "loop" in his code.

okay thanks, I'm used to doing:

int main(void) {

i havent programmed for arduino but i think you will need a main loop

You don't need those extra brackets you got there in the main loop. The code you show above should only have 2 sqiggily brackets total for the main loop.

The real question is:  Why did you ask the question? One great way to confirm if the code will work or not is to put the code into your arduino and see if it works or not. Did it?

I don't have my board yet. I'm just asking to see whether it will do it's job or not. Thnx BTW!