Servo Control

I am working on a project that will control my window blinds depending on the input of a LDR. e.g If it is light outside the blinds will open, if it is dark outside the blinds will shut. There isn’t a lot of code out there for controlling servos so I have had to take bits n pieces from various sources. To test the servo I need to have it spinning for so many seconds CW… pause for so many seconds… then spin CCW for so many seconds. This is to check how long it will take to open/shut them. I am using a modified servo that spins 360 continuous.

This is what I have, but the delay doesn’t seem to work.


#include <Servo.h>

Servo servo;

void setup()

{
servo.attach(10);
}

void loop()

{
bbservo_move(6000, 70);
delay(3000);
bbservo_move(2600, 110);
delay(3000);
}

void bbservo_ccw_move(int duration, int velocity)
{
for (int i=velocity; i <=80 ; i++){
servo.write(i);
delay(3000);
}
}

void bbservo_cw_move(int duration, int velocity)
{
for (int i=velocity; i >=90 ; i–){
servo.write(i);
delay(3000);
}
}

void bbservo_move(int duration, int velocity)
{
servo.write(velocity);
delay(3000);
}


Any help would be appreciated.
Cheers

the delay doesn’t seem to work

Which one? I see five of them.

Well I thought that the ones in the loop would perform the move.. wait 3 seconds then perform the next move. The other delays were already in the code at 1000 so I just changed them to 3000 to see if the would delay after the move too.

Can you post: 1) What you expect to happen 2) What you observe happening.

The functions bbservo_ccw/cw_move aren't being called. You've defined them, but not called them in loop() - nor anywhere else.

  1. I expect the servo to turn Clock Wise for 5 seconds and stop.

Pause for 5 seconds

Then to turn Counter Clock Wise for 5 seconds and stop.

It doesn't need to be in a continuous loop just a one off.

  1. What actually happens is the servo turns CW stops and then turns CCW straight away leaving no Pause in between.

Thanks

Six seconds I could probably understand, but not five.

You don't have any calls to stop the servo, that's why it goes from one direction straight to the other.

A simple way of stopping a continuous servo is to call "detach", then call "attach" just before you want to move it again.

thanks :)