Hi everybody.
This code taken from this forum moves bust eyes in two axis connected to pin 9 & 10.
the delay(20) controls interval between one move and the next.
It works fine, but the only obstacle is how to control the servo movement.
Need to make them move very slow. how to do that ??
#include <Servo.h> //include servo library for servo control
Servo xservo;
Servo yservo;
int xpos;
int ypos;
void setup()
{
xservo.attach(9);
yservo.attach(10);
}
void loop()
{
{
ypos = random(180); //generate random value for y-servo
yservo.write(ypos); //y-servo moves to new position
delay(20);
}
{
xpos = random(180); //generate random value for x-servo
xservo.write(xpos); //x-servo moves to new position
delay(20);
}
}
You will need to restructure your program. You can't pick a new position for the servo until the servo has finished moving to the last position you told it to go to.
You could use the sweep example that zoomkat refers to, with it's delay()s that prevent your code from doing anything else. Or, you could use the blink without delay example's philosophy, instead, and, rather than toggling the state of an LED, move the servo a small amount.
When the servo, through a series of small moves with periods of inactivity (on the part of the serve, not on the part of the Arduino) gets to the position you picked for it to go to, then you pick another position to go to.