//arduino code controlling servo by analog joystick. servo is conedted to D3 pin PWM, analog joystick horisontal is connected to A0, vertical to A1
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards
int pinSlide = A5;
int posx = 0; // variable to store the servo position
int posy = 0;
int x = 0;
int y = 0;
void setup() {
myservo1.attach(3); // attaches the servo on pin 9 to the servo object
myservo2.attach(4);
pinMode(pinSlide, INPUT);
Serial.begin(9600);
}
void loop() {
x = analogRead(A0);
y = analogRead(A1);
pinSlide = analogRead(pinSlide)
Serial.print("x = ");
Serial.print(x);
Serial.print(" y = ");
Serial.println(y);
delay(100);
if (x > 600) {
posx = posx + 2;
if (posx > 180) {
posx = 180;
}
}
if (x < 400) {
posx = posx - 1;
if (posx < 0) {
posx = 0;
}
}
//for other servo vertical
if (y > 600) {
posy = posy + 5;
if (posy > 180) {
posy = 180;
}
}
if (y < 400) {
posy = posy - 5;
if (posy < 0) {
posy = 0;
}
}
myservo1.write(posx);
myservo2.write(posy);
delay(10);
}