#include <Servo.h>
//using servors
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 12
//global varialble joystick and servo val, time ect.
int horz;
int vert;
int pos1 = 0;
int servval1;
int servval2;
int servval4;
int servval3 = 0;
int dt = 100;
//int buttonVal;
int Button2 = 7;
int buttonVal2;
void setup() {
//define my pin servos
myservo1.attach(11);
myservo2.attach(10);
myservo3.attach(9);
myservo4.attach(6);
// define my joystick pins
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
//pinMode(SEL_PIN, INPUT_PULLUP);
pinMode(Button2, INPUT_PULLUP);
}
void loop() {
//first position of servos when they are gonna start
myservo1.write(pos1);
myservo2.write(pos1);
myservo3.write(pos1);
myservo4.write(pos1);
buttonVal2 = digitalRead(Button2);
Serial.begin(9600);
if(buttonVal2 == 1){
//buttonVal2 = digitalRead(Button2);
myservo3.write(90);
myservo1.write(servval1);
myservo2.write(servval2);
myservo4.write(servval4);
Serial.println(buttonVal2);
delay(500);
}
else if(buttonVal2 == 0) {
myservo1.write(servval1);
myservo2.write(servval2);
myservo4.write(servval4);
myservo3.write(buttonVal2);
Serial.println(buttonVal2);
delay(500);
}
//first if for hand uses
if(digitalRead(SEL_PIN == LOW)){
servval4 = map (digitalRead(SEL_PIN), 0, 1, -100, 100 );
myservo3.write(servval3);
myservo1.write(servval1);
myservo2.write(servval2);
myservo4.write(servval4);
delay(10);
}
else
{
myservo3.write(servval3);
myservo1.write(servval1);
myservo2.write(servval2);
myservo2.write(servval4);
}
// second if and first else for uses of servo1 to move the based of our robotic arm
if (horz = analogRead(HORZ_PIN))
{
servval1 = map (analogRead(HORZ_PIN), 0, 512, -100, 100 );
myservo1.write(servval1);
delay(dt);
}
else
{
servval1 = map (analogRead(HORZ_PIN), 0, 1023, -100, 100 );
myservo1.write(servval1);
delay(dt);
}
// third if and second else for uses of servo2 to move the second part or up part of our robotic arm
if (vert = analogRead(VERT_PIN))
{
servval2 = map (analogRead(VERT_PIN), 0, 512, -100, 100 );
myservo2.write(servval2);
delay(dt);
}
else
{
servval2 = map (analogRead(VERT_PIN), 0, 1023, -100, 100 );
myservo2.write(servval2);
delay(dt);
}
}