#include <Servo.h> //include servo library
Servo servo1; // creating servo object
Servo servo2;
Servo servo3; // creating servo object
Servo servo4;
Servo servo5;
int joystick_x = A0; // joystick x direction pin
int joystick_y = A1; // joystick y direction pin
int joystick_x1 = A2; // joystick x direction pin
int joystick_y1 = A3; // joystick y direction pin
int pos_x; // declaring variable to stroe horizontal value
int pos_y; // declaring variable to stroe vertical value
int pos_x1; // declaring variable to stroe horizontal value
int pos_y1;
String pos_xs, pos_ys;
String pos_x1s, pos_y1s, pots;
int servo1_pos = 90; // storing servo position
int servo2_pos = 90;
int servo3_pos = 90; // storing servo position
int servo4_pos = 90;
int potpin = 4; // analog pin used to connect the potentiometer
int pot; // variable to read the value from the analog pin
void setup ( )
{
Serial.begin (9600) ;
servo1.attach (2) ; // servo 1 attached pin
servo2.attach (3) ; // servo 1 attached pin
servo3.attach (4) ; // servo 1 attached pin
servo4.attach (5) ;
servo5.attach (6) ;
servo1.write (servo1_pos);
servo2.write (servo2_pos);
servo3.write (servo3_pos);
servo4.write (servo4_pos);
pinMode (joystick_x, INPUT) ;
pinMode (joystick_y, INPUT) ;
pinMode (joystick_x1, INPUT) ;
pinMode (joystick_y1, INPUT) ;
}
void loop ( )
{
pos_x = analogRead (joystick_x) ;
pos_y = analogRead (joystick_y) ;
pos_x1 = analogRead (joystick_x1) ;
pos_y1 = analogRead (joystick_y1) ;
pot = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
pot = map(pot, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo5.write(pot); // sets the servo position according to the scaled value
delay(15);//*/
pos_xs = String (pos_x);
pos_ys = String(pos_y);
pos_x1s = String(pos_x1);
pos_y1s = String(pos_y1);
pots = String(pot);
Serial.println('*' + pos_xs + ',' + pos_ys + ',' + pos_x1s + ',' + pos_y1s + ',' + pots + '#');
delay(1000);
//---------------------------------------------
}