Arduino Forum

Topics => Robotics => Topic started by: pittom on Nov 21, 2011, 09:09 pm

Title: servo help
Post by: pittom on Nov 21, 2011, 09:09 pm
Hi,I need to move 4 servo with a uno

example
-servo 1 on pin ? goes from pos 0 to 24 when input pin 3 goes high and servio 1 goes back to pos 0 when pin 3 goes low

-servo 2,3,4  output will all have there own input high/low pin

any help would be great
thanks
Title: Re: servo help
Post by: johnwasser on Nov 21, 2011, 11:55 pm
Code: [Select]

void loop()
   {
if (digitalRead(3))
    servo1.write(24);
else
    servo1.write(0);

if (digitalRead(x))
    servo2.write(24);
else
    servo2.write(0);

if (digitalRead(y))
    servo3.write(24);
else
    servo3.write(0);

if (digitalRead(z))
    servo4.write(24);
else
    servo4.write(0);
}
Title: Re: servo help
Post by: pittom on Nov 22, 2011, 02:31 am
i can't get the servo and input pin setup,how would i do it? every thing i tried did not work
Title: Re: servo help
Post by: zoomkat on Nov 22, 2011, 03:42 am
Simple button servo setup.

Code: [Select]

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}