#include <MPU6050.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <Servo.h>
//Servo objects created to control the servos
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
Servo myServo5;
Servo myServo6;
Servo myServo7;
int potentio = 14;
int servo1 = 13; //Digital PWM pin used by the servo 1
int servo2 = 12; //Digital PWM pin used by the servo 2
int servo3 = 11;
int servo4 = 10;
int servo5 = 9;
int servo6 = 7;
int servo7 = 6;
int joyX = 13; //Analog pin to which the joystick (X) is connected
int joyY = 12; //Analog pin to which the joystick (Y) is connected
void setup(){
myServo1.attach(servo1);
myServo2.attach(servo2);
myServo3.attach(servo3);
myServo4.attach(servo4);
myServo5.attach(servo5);
myServo6.attach(servo6);
myServo7.attach(servo7);
}
void loop(){
int valX = analogRead(joyX); //Read the joystick X value (value between 0 and 1023)
int valY = analogRead(joyY); //Read the joystick Y value (value between 0 and 1023)
int val = analogRead(potentio);
val = map(val, 0, 1023, 0, 180);
valX = map(valX, 0, 1023, 0, 180); //Scale the joystick X value to use it with the servo
valY = map(valY, 0, 1023, 0, 180); //Scale the joystick X value to use it with the servo
//Sets the servo position according to the scaled values.
myServo1.write(valX);
myServo2.write(valY);
myServo3.write(val);
myServo4.write(valY);
myServo5.write(valX);
myServo6.write(valY);
myServo7.write(valX);
delay(5);
}