#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
void setup() {
// Servo button by me(maneth)
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");
}
void loop() {
// Servo button thumb right
while(digitalRead(RIGHTthumb) == LOW){
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo1.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}// while
// Servo button thumb left
while(digitalRead(LEFTthumb) == LOW){
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo1.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}//
// Servo button index
int value2 = analogRead(A2);
value2 = map(value2, 0, 1023 , 0, 180);
myservo2.write(value2);
delay(20);
// Servo button middle
int value3 = analogRead(A3);
value3 = map(value3, 0, 1023 , 0, 180);
myservo3.write(value3);
delay(20);
// Servo button ring
int value4 = analogRead(A4);
value4 = map(value4, 0, 1023 , 0, 180);
myservo4.write(value4);
delay(20);
// Servo button pinky
int value5 = analogRead(A5);
value5 = map(value5, 0, 1023 , 0, 180);
myservo5.write(value5);
delay(20);
/* // Servo button
while(digitalRead(RIGHT) == LOW){
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}// while
// Servo button
while(digitalRead(LEFT) == LOW){
// Servo button
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}// */
/* // Servo button
while(digitalRead(RIGHT) == LOW){
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}// while
// Servo button
while(digitalRead(LEFT) == LOW){
// Servo button
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100); // waits for the servo to get there
}// */
}