i want to make a pan/tilt camera mount, i tried doing it myself using the code attached, then i realized aout one thing, when you want to call a pin on the arduino, how do you call the analog pins and the pwm pins? lets say i have something on ANALOG pin #3, and something else on PWM pin#3, how do you call these pins on the code? A3? AND ~3?
and i tried, it works, but it doesn't work the way id like it to work, when i move the joystick it responds, but when you don't move the joystick "neutral position" the servo goes back to its original position, but i want the servo to stay on the position i left it with the joystick, how can i do that? i know the code i found converts the read value (voltage) to a certain PWM duty cycle giving a certain turn angle, but how can i make it stay put and not go back to neutral position? any suggestions
lets say i have something on ANALOG pin #3, and something else on PWM pin#3, how do you call these pins on the code? A3? AND ~3?
The analog pin 3 is referenced:
int val = analogRead(3);
The digital pin 3 is referenced:
int val = digitalRead(3);
// or
digitalWrite(3, HIGH);
// or
analogWrite(3, 127);
When using an analog pin as a digital pin:
int val = digitalRead(A3);
// or
digitalWrite(A3, LOW);
No ~s anywhere.
and i tried, it works, but it doesn't work the way id like it to work, when i move the joystick it responds, but when you don't move the joystick "neutral position" the servo goes back to its original position, but i want the servo to stay on the position i left it with the joystick, how can i do that?
Don't let go of the joystick. The code has no idea when you want to read the joystick and move the servos vs. when you don't.
You could add a switch that you use to determine whether to read the joystick and move the servos, or not.
Does your joystick have a pushbutton on top? Or some kind of trigger?
You could change your software so that the distance of the joystick from the centre position defines the rate at which the servo moves in the desired direction, not the absolute position.
AWOL has the right answer. When you read in on the x and y pin from the joystick rather than converting to and RC servo signal you need to integrate that signal. You then pump the integrated signal to the RC servo. If you have difficulty with it get back to me as I have done this before and can dig up the code.
Sara.
// Controlling movements of two servos using a Joystick
// Joystick's x- and y- axes are connected to A0 and A1 analog pins of Arduino.
// Servos are connectd to PWM Pins 9 and 10.
// By Explore Labs
#include <Servo.h>
Servo tilt, pan; // create servo object to control a servo
int joyX = A0; // analog pin used to connect the X - axis of Joystick
int joyY = A1; // analog pin used to connect the Y - axis of Joystick
int x, y; // variables to read the values from the analog pins
void setup()
{
tilt.attach(9); // attaches the tilt servo on pin 9 to the servo object
pan.attach(10); // attaches the pan servo on pin 10 to the servo object
}
void loop()
{
x = joyX; // reads the value of the Joystick's X - axis (value between 0 and 1023)
y = joyY; // reads the value of the Joystick's Y - axis (value between 0 and 1023)
x = map(analogRead(joyX), 0, 1023, 900, 2100); // scale it to use with the servo b/w 900 usec to 2100 usec
y = map(analogRead(joyY), 0, 1023, 900, 2100);
tilt.write(x); // sets the servo position according to the scaled value
pan.write(y);
delay(15); // waits for the servos to get there
}