#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int VRy = A0;
int VRx = A1;
int SW = 3;
int VRx2 = A2;
int VRy2 = A3;
int SW2 = 6;
int posXJ1 = 0;
int posYJ1 = 0;
int posXJ2 = 0;
int posYJ2 = 0;
void setup() {
// put your setup code here, to run once:
servo1.attach(9);
servo2.attach(10);
servo3.attach(11);
servo4.attach(12);
pinMode(VRx, INPUT);
pinMode(VRy, INPUT);
pinMode(SW, INPUT_PULLUP);
pinMode(VRx2, INPUT);
pinMode(VRy2, INPUT);
pinMode(SW2, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int xPosition1 = analogRead(VRx);
int yPosition1 = analogRead(VRy);
int mapX1 = map(xPosition1, 0, 1023, -1.5, 1.5);
int mapY1 = map(yPosition1, 0, 1023, -1.5, 1.5);
posXJ1+=mapX1;
posYJ1+=mapY1;
if (posXJ1>180)
{
posXJ1 = 180;
}
else if(posXJ1<0)
{
posXJ1 = 0;
}
if (posYJ1>180)
{
posYJ1 = 180;
}
else if(posYJ1<0)
{
posYJ1 = 0;
}
Serial.println( xPosition1);
int xPosition2 = analogRead(VRx2);
int yPosition2 = analogRead(VRy2);
int mapX2 = map(xPosition2, 0, 1023, -1.5, 1.5);
int mapY2 = map(yPosition2, 0, 1023, -1.5, 1.5);
posXJ2+=mapX2;
posYJ2+=mapY2;
if (posXJ2>180)
{
posXJ2 = 180;
}
else if(posXJ2<0)
{
posXJ2 = 0;
}
if (posYJ2>180)
{
posYJ2 = 180;
}
else if(posYJ2<0)
{
posYJ2 = 0;
}
servo2.write(posXJ1);
servo3.write(posYJ1);
servo1.write(posXJ2);
servo4.write(posYJ2);
}