#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
Servo myservo3; // create servo object to control a servo
Servo myservo4; // create servo object to control a servo
Servo myservo5; // create servo object to control a servo
int servoPin1 =9;
int servoPin2 =10;
int servoPin3 =11;
int servoPin4 =12;
int servoPin5 =13;
int angle =0; // initial angle for servo
int angleside =180; // initial angle for servo
int angleStep =5;
#define LEFTthumb 0 // pin 0 is connected to left button
#define RIGHTthumb 1 // pin 1 is connected to right button
#define LEFTall 2 // pin 0 is connected to left button
#define RIGHTall 3 // pin 1 is connected to right button
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // setup serial
myservo1.attach(servoPin1); // attaches the servo on pin 9 to the servo object
myservo2.attach(servoPin2); // attaches the servo on pin 9 to the servo object
myservo3.attach(servoPin3); // attaches the servo on pin 9 to the servo object
myservo4.attach(servoPin4); // attaches the servo on pin 9 to the servo object
myservo5.attach(servoPin5); // attaches the servo on pin 9 to the servo object
pinMode(LEFTthumb,INPUT_PULLUP); // assign pin 0 as input for Left button
pinMode(RIGHTthumb,INPUT_PULLUP);// assing pin 1 as input for right button
myservo1.write(angle);// send servo to the middle at 0 degrees
Serial.println(" Servo Button 1");
Serial.println(" Servo Button 2");
Serial.println(" Servo Button 3");
Serial.println(" Servo Button 4");
Serial.println(" Servo Button 5");
}
void loop() {
// Servo button all
while(digitalRead(RIGHTall) == LOW){
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo1.write(angle); // move the servo to desired angle
int value2 = analogRead(A2);
value2 = map(value2, 0, 1023 , 0, 180);
myservo2.write(value2);
int value3 = analogRead(A3);
value3 = map(value3, 0, 1023 , 0, 180);
myservo3.write(value3);
int value4 = analogRead(A4);
value4 = map(value4, 0, 1023 , 0, 180);
myservo4.write(value4);
int value5 = analogRead(A5);
value5 = map(value5, 0, 1023 , 0, 180);
myservo5.write(value5);
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(50); // waits for the servo to get there
}// while
// Servo button all
while(digitalRead(LEFTall) == LOW){
// Servo button
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo1.write(angle); // move the servo to desired angle
int value2 = analogRead(A2);
value2 = map(value2, 0, 1023 , 0, 180);
myservo2.write(value2);
int value3 = analogRead(A3);
value3 = map(value3, 0, 1023 , 0, 180);
myservo3.write(value3);
int value4 = analogRead(A4);
value4 = map(value4, 0, 1023 , 0, 180);
myservo4.write(value4);
int value5 = analogRead(A5);
value5 = map(value5, 0, 1023 , 0, 180);
myservo5.write(value5);
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(50); // waits for the servo to get there
}//
}