The reason for this question: I'm still hoping to just use a servo to open and close a drawer (the drawer is actually a platform on which a coffee pot sits in a cupboard). I know a servo is not designed to be used this way, but it would save having to rig up extra sesnors/limit switches, and a servo is easy to use. Being it's just used a few seconds a day thing, maybe it'll work for years.
Here's my first run at code for it. Does it look promising?
/* servo speed:
0 full speed reverse
90 stopped
180 full speed forward
*/
Servo myservo; // create servo object to control a servo
void Servo_Out()
{
myservo.attach(ServoPin); // attaches the servo on pin 9 to the servo object
lcd.clear();
lcd.print("1 coffeepot coming up, er, out.");
int intDelay = 20; //changing delay will change the overall distance.
int x = 1;
for (int i = 91; i > 90; i = i + x){ //loop from 90 to 179 and back to 90
myservo.write(i); // sets the servo speed
if (i = 179) x = -1; // start to slow down at full speed
delay(intDelay); // set distance to 0.5" longer than drawer travel
}
myservo.detach(); // detaches the servo on pin 9 to the servo object
}