I'm looking for a little help, guidance, ideas.
I found a sketch on a closed forum http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246742084 here that looked to be just about exactly what I needed. It was originally written as a two button, one servo controller with a few minor errors that were easily corrected. I can attach the original sketch if anyone wants to see it.
After correcting the errors and testing the sketch as I went, I started to add an additional servo and an additional separate button set to control that servo. Testing as I went along. It works great! EXCEPT! And here is where I need a little help:
If I use myservo1 going either forward or reverse by pushing one of its two attached buttons and then do the same for myservo2, that servo slews about 20°. The same thing happens if I to this in the reverse; the second servo slews or jumps 20° sometimes forward, sometimes backwards.
Here is the sketch:
(Thanks mem)
#include <Servo.h>
Servo myservo1; // define servo aliases
Servo myservo2;
#define leftPin 2 // define buttons attached to pins
#define rightPin 3
#define upPin 4
#define downPin 5
int pos = 90; // set angle when inialitized
int delayPeriod = 150; // increasing this slows down the servo slew movement
// 1000 too much 300 jumpy 100 smooth slew 80 fast 50 too fast 70 testing
void setup()
{
myservo1.attach(10); // attaches the servo on pin 9 to the servo object
myservo2.attach(9); // attaches the servo on pin 10 to the servo object
myservo1.write(pos); // center the servo from inialitization
myservo2.write(pos); // center the servo from inialitization
pinMode(leftPin, INPUT);
pinMode(rightPin, INPUT);
pinMode(upPin, INPUT);
pinMode(downPin, INPUT);
digitalWrite(leftPin, HIGH); // turn on pullup resistor
digitalWrite(rightPin, HIGH); // turn on pullup resistor
digitalWrite(upPin, HIGH); // turn on pullup resistor
digitalWrite(downPin, HIGH); // turn on pullup resistor
// left/right servo control
}
void loop()
{
if(digitalRead(leftPin) == HIGH) // left button instructions
{
// in steps of 1 degree
if( pos > 0)
--pos;
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
if(digitalRead(rightPin) == HIGH) // right button instructions
{
if( pos < 180)
++pos;
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
// up/down servo control
{
if(digitalRead(upPin) == HIGH) // up button instructions
{
// in steps of 1 degree
if( pos > 0)
--pos;
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
if(digitalRead(downPin) == HIGH) // down button instructions
{
if( pos < 180)
++pos;
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
} }
Any ideas?
Am I missing something?
This is my first real sketch and I am a veteran of Arduino for a total of six days!
I have tried tons of things! namely changing the parameters of the pinMode, adding and deleting digitalWrite, Playing with the delayPeriod timing.
I have also tried to play with the pull-down resistors only to find out that if i use a 10k, 4.7k or even a 220? the buttons do not respond. I'm currently using a 270? pull-down and the servos no longer chatter.
Again, any ideas?
I'm using it to control the x-y axis of a security camera via a switched joy stick controller.
I would really like to solve this puzzle. But if anybody has a different sketch that accomplish this I would really appreciate taking a gander at it.
Thank you all in advance.
Peace.