Hi, I have added an example that controls a Servo based Pan-Tilt kit from a joystick to the http://ArduinoInfo.Info WIKI. (Link at top) This is part of the overall Potentiometer / Joystick How-To.
I took a quick look and the delay below may be just an artifact from the servo "sweep" example. A delay does come in handy when printing to the serial monitor for observing values being generated.
delay(25); // wait for the servo to reach the position
I took a quick look and the delay below may be just an artifact from the servo "sweep" example.
Hey Zoom,
Yes, there's nothing significant about that. Probably anyone doing something significant will need to think the Loop through and may well not have any intentional delay.
What I did see was that making that delay 250ms made the control seem "shaky". Technically Speakin' .
I had a couple of requests for HowTo do this, so I put it out. One guy is making a "Camera Pole" with pan/tilt control. It would be interesting to code some smoothing stuff and variable-rate move algorithm for that kind of application.
Thanks for your many code examples...
I made the below for future tinkering with joystick/pot servo control via an Ethernet/internet connection. It has a delay and dead band to make serial monitor viewing of what is going on easier, and to prevent an unneeded control position spew which might overload the receiving end. I haven't had a servo hooked up in quite a while, so I need to get back on that.
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int potpin1 = 0; //analog input pin A0
int potpin2 = 1;
int newval1, oldval1;
int newval2, oldval2;
void setup()
{
Serial.begin(9600);
myservo1.attach(2);
myservo2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newval1 = analogRead(potpin1);
newval1 = map(newval1, 0, 1023, 0, 179);
if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){
myservo1.write(newval1);
Serial.print("1- ");
Serial.println(newval1);
oldval1=newval1;
}
newval2 = analogRead(potpin2);
newval2 = map(newval2, 0, 1023, 0, 179);
if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){
myservo2.write(newval2);
Serial.print("2- ");
Serial.println(newval2);
oldval2=newval2;
}
delay(50);
}
servo pan tilt control with potentiometer and arduino uno this code Robimek
sezgin:
servo pan tilt control with potentiometer and arduino uno this code http://www.robimek.com/potansiyometre-ile-pan-tilt-kontrol-etme/
Simple code, but powering the servos from the arduino per the diagram will probably cause problems.
When I recently experimented with a joystick and a pan and tilt device I found there was a noticeable improvement to using "writeMicroseconds" over the usual "write" command.
I suppose I can kind understand why "write" is so frequently used in servo projects but I personally think it's a bad idea to use "write" instead of "writeMicroseconds".
I posted an overly complex example of using "writeMicroseconds" in this thread. The code includes a ring buffer to smooth out the readings from the analog input.
I certainly don't expect to win my crusade to replace "write" with "writeMicroseconds" in Arduino servo examples but I hope you don't mind my proselytizing on the subject in this thread.
BTW, That's a very nice looking page on using pots.