Ok I need a little help with this. What im trying to do is make my servo move right when i hold down button 1, or move left when i hold down button 2. I say hold down said buttons because if i let go of the button i want the servo to stop and stay.
I need help setting up the hardware and software.
I'm using buttons or "High" and "Low" because in the end im going to be using a 2 button wireless rf controller to move the servo. Should be an ez way to move the servo wireless for pan and tilt on my outside cams, but i'm sure if i can get this working there will be much more things that can be down with it.
Here is (an untested) modification to one of the Servo example sketches that should get you going in the righ direction
#include <Servo.h>
Servo myservo;
#define leftPin 2
#define rightPin 3
int pos = 90;
int delayPeriod = 50; // increasing this slows down the servo movement
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos); // center the servo
pinMode(leftPin, HIGH); // turn on pullup resistors
pinMode(rightPin, HIGH);
}
void loop()
{
if(digitalRead(leftPin) == LOW)
{
// in steps of 1 degree
if( pos > 0)
--pos;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
if(digitalRead(rightPin) == LOW)
{
if( pos < 180)
++pos;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
}
could you do me a favor and edit out the scrolling text in your post, I find it very distracting
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos); // center the servo
pinMode(leftPin, HIGH); // turn on pullup resistors
pinMode(rightPin, HIGH);
}
To ensure that when the button is not pushed the input receives a steady logic one. Without it the input will float and give random values of HIGH and LOW.