For a project that I've been working on, I have made a robotic arm out of 3D printed parts and arduino. I use 6 servos. 3 of the bigger black servos, and 3 of the smaller blue servos. I am also using 2 of the joysticks to control them. My first issue is that I can't use the button to be able to control the servos with the buttons on the joysticks. My second issue is that when I try to move the smaller blue servos with the joysticks, they spas out and spin like crazy. But when I hook the bigger servos up to the code they work fine. IDK whats wrong with my code. ATM I only have 3 servos programmed. Here is my code, sorry I don't comment and make notes of what I do:
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
int x_key = A1;
int y_key = A0;
int y_key1 = A2;
int push = 7;
int x_pos;
int y_pos;
int x_pos1;
int y_pos1;
int pushval;
int servo1_pin = 8;
int servo2_pin = 9;
int servo3_pin = 10;
int initial_position = 90;
int initial_position1 = 90;
int initial_position2 = 50;
void setup ( ) {
Serial.begin (9600) ;
servo1.attach (servo1_pin ) ;
servo2.attach (servo2_pin ) ;
servo3.attach (servo3_pin);
servo1.write (initial_position);
servo2.write (initial_position1);
servo3.write (initial_position2);
pinMode (x_key, INPUT) ;
pinMode (y_key, INPUT) ;
pinMode (push, INPUT);
}
void loop ( ) {
x_pos = analogRead (x_key) ;
y_pos = analogRead (y_key) ;
y_pos1 = analogRead (y_key1);
pushval = digitalRead(push);
//servo3.read();
Serial.println(servo3.read());
if (x_pos < 300) {
if (initial_position < 10) { } else {
initial_position = initial_position - 10;
servo1.write ( initial_position ) ;
delay (100) ;
}
} if (x_pos > 700) {
if (initial_position > 180)
{
}
else {
initial_position = initial_position + 10;
servo1.write ( initial_position ) ;
delay (100) ;
}
}
if (y_pos < 300) {
if (initial_position1 < 60) {
initial_position1 + 10;
} else {
initial_position1 = initial_position1 - 10;
servo2.write ( initial_position1 ) ;
delay (100) ;
}
} if (y_pos > 700) {
if (initial_position1 > 180)
{
}
else {
initial_position1 = initial_position1 + 10;
servo2.write ( initial_position1 ) ;
delay (100) ;
}
}
if (y_pos1 < 300) {
if (initial_position2 < 60) {
initial_position2 + 10;
} else {
initial_position2 = initial_position2 - 10;
servo3.write ( initial_position2 ) ;
delay (100) ;
}
} if (y_pos1 > 700) {
if (initial_position2 > 180)
{
}
else {
initial_position2 = initial_position2 + 10;
servo3.write ( initial_position2 ) ;
delay (100) ;
}
}
}
Also, most of this is code from other peoples projects that I have dissected and converted into my own code.
