Code help.

Hi gang, just wondering if I could get some help with some simple code please?? I have a pan/tilt servo set up and need X servo to turn 1 degree for 360 degrees. Then at the completion of each 1 degree turn by X servo I would like Y servo to turn 180 degrees?

Any help would be extremely appreciated until I get into the swing of things with Arduino?

Cheers Packman.

Something like

for (x=0; x<360; x++)
{
   xservo.write(x)
   for (y=0; y<180; y++)
   {
      yservo.write(y);
      delay(1000);
   }

}

Of course this may not work but it should give you a starting point for the logic.

thanks rw, I am new to Arduino but need this urgently for a photo I am taking! Thx for the help

Packman_in_OZ:
Hi gang, just wondering if I could get some help with some simple code please?? I have a pan/tilt servo set up and need X servo to turn 1 degree for 360 degrees.

More information is needed.
A standard servo can’t turn 360 degrees. What sort of servo are you using?

Then at the completion of each 1 degree turn by X servo I would like Y servo to turn 180 degrees?

A standard servo’s full swing is about 180 degrees. Do you mean you want it to turn 180 degrees in one direction the first time, then 180 degrees in the other direction the next time etc?
Once again, more information is needed.

If you’re using continuous-rotation servos, none of the above is possible.

rw950431:

for (x=0; x<360; x++)

The servo library will immediately change the 360 to 180, so this won’t work.
(Any value from 181 to 543 is changed to 180.)
The ‘write()’ function:-

void Servo::write(int value)
{
    if (value < MIN_PULSE_WIDTH)
    {
        // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
        if (value < 0) value = 0;
        if (value > 180) value = 180;
        value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
    }
    this->writeMicroseconds(value);
}