Hello all,
i am a noob to the arduino world. i built a pan/tilt camera system for my rc car. i have the generic code for the x and y axis and have that working fine, but i would like the camera to stay in the last position that i directed it to and then recenter with the system with the button press in the joystick. i dont have the button added to the code just yet nor the write to serial bc i am trying to get the main action resolved first.
hardware:
arduino nano
4 servos ( other 2 are for zoom and other function)
2 axis joystick with momentary button
code :
Servo panServo; // Create a servo object for the pan (horizontal) servo
Servo tiltServo; // Create a servo object for the tilt (vertical) servo
Servo zoomServo; // Create a servo object for zoom (left/right) servo
Servo downServo; // Create a servo obhect for record (down/up) servo
int panPin = 0; // Analog input for the joystick pan axis
int tiltPin = 1; // Analog input for the joystick tiltl axis
int zoomPin = 2; // Analog input for the zoom joystick axis
int downPin = 3; // Analog input for the down axis
int tiltVal; // Value read from the vertical axis
int panVal; // Value read from the horizontal axis
int zoomVal; // Value read from the zoom axis
int downVal; // Value read from the down axis
void setup()
{
panServo.attach(9); // use pin 9 PWM output for pan servo
tiltServo.attach(10); // use pin 10 PWM output for tilt servo
zoomServo.attach(6); // use pin 6 PWM output for zoom servo
downServo.attach(5); // use pin 5 PWM output for down servo
}
void loop ()
{
panVal = analogRead(panPin); // read pan joystick position
panVal = map(panVal, 0, 1023, 0, 179); // scale reading to servo
panServo.write(panVal); //move servo to required position
tiltVal = analogRead(tiltPin); // read pan joystick position
tiltVal = map(tiltVal, 0, 1023, 0, 179); // scale reading to servo
tiltServo.write(tiltVal); //move servo to required postion
zoomVal = analogRead(zoomPin); // read zoom joystick position
zoomVal = map(zoomVal, 0, 1023, 0, 179); // scale reading to servo
zoomServo.write(zoomVal); //move servo to required position
downVal = analogRead(downPin); // read record joystick position
downVal = map(downVal, 0, 1023, 0, 179); // scale reading to servo
downServo.write(downVal); //move servo to required position
}
Any and all help/advice would be gratefully appreciated in this little DIY project of mine.
Thanks in advance