Let's Make Robots!

arduino code

im working on the ankle servos, so im just using the example sweep, an i have them zeroed at 90 deg. I can get it from 90 to 180 an back but i cant get it to go 90 - 0.   

 

 

 

#include <Servo.h> 

 

Servo myservo;  // create servo object to control a servo 

 

 

int pos = 90;   

 

void setup() 

  myservo.attach(9);  

 

 

void loop() 

  for(pos = 90; pos > 45; pos += 1)  // goes from 0 degrees to 180 degrees 

  {                                  // in steps of 1 degree 

    myservo.write(pos);            

    delay(15);                      

  } 

  for(pos = 45; pos <=90; pos-=1)    

  {                                

    myservo.write(pos);              

 

    delay(15);                    

 

  } 

 

Comment viewing options

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

We have some issues with your numbers in the for loops. The first for-loop as you have it written now is:

Start at 90; as long as pos is greater than 45 then; increase by one each loop

This loop will be skipped in the fact that 90 is already bigger than 45. The reverse is the case for your second loop. As it just-so-happens, I have something that might help.

https://sites.google.com/a/rocketbrandstudios.com/rocket-brand-studios/tutorials/tutorials-lmr-tadpole-main/tutorials-lmr-servo

This is a tutorial I did for the new LMR Tadpole bot, but it covers servos and for-loops. It should clear up a lot.