void fn( int pin, int pos)
{
Servo temp;
temp.attach(pin);
temp.write(pos);
delay(15);
temp.detach();
}
void loop()
{
int pos = 0 ;
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
//tmp2.write(pos);
//delay(15);
fn(41,pos);
fn(2,180 - pos);
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
fn(41,pos);
fn(2,180 - pos);
}
}
But when I run the code in mega , the servo does not move when attached to pin 2 or 41. The reason I am creating a function fn , is so that the servo does not stay attached. I want the servo to rotate freely when I am not giving it a pwm signal.