Delay code issues for Baby-O driving a servo

I am using an AVR USB programmer with AVR Studio4 (Windows XP) to program a Baby-Orang B-328 to drive a servo on PD0. This is very simple code (I am just learning) designed to simply sweep the servo from one position to another and then back. There is then a delay for a prescribed period of time (say 5 minutes) before repeating the cycle. The cycle should run continuously with a sweep every 5 mins approx.

When I run this code, the servo completes one arc only. The delay_ms() code does not appear to be working properly and the program does not repeat either…any advice or help is appreciated.

Here is my code:

[code]#define F_CPU 20000000
#include <pololu/orangutan.h>

#include <util/delay.h>

int main()



// set output pin for servo to PD0
const unsigned char demuxPins[] = {IO_D0};
servos_init(demuxPins, sizeof(demuxPins));

//initialize variables

    int numWipes = 1;                // set number of wipes per cycle

    int numDelay = 5;                // set number of delay period to repeat before main loop
    int x;
    int y;

    //int sleepTime = 1;                // set sleep time between cycle (minutes)

//this is a wipe-cycle that is usually set to 1

    for(int y = 0; y != numWipes; ++y)

     //sweep code

set_servo_target(0, 2000);  // Make the servo go to a FIRST position.
     set_servo_target(0, 750);  // Make the servo go to a REST position.

//time delay - numDelay cycles in minutes

    for(int x = 0; x != numDelay; ++x)

    //sleep for desired sleepTime (minutes)







I am sorry you are having problems moving servos with your Baby Orangutan. I briefly looked at your code, and it looks like your while loop initializes the servo pins more than once. I recommend moving the initialization outside the while loop. It also looks like you might be missing brackets around your “sweep code” when declaring the for loop. Without the brackets, the for loop will set the servo target to the same location multiple times.

- Jeremy

Jeremy - thanks very much for your help. I fixed the problem and it now works fine. Cheers!